Commit 15cecc5a authored by RAYMOND XIA's avatar RAYMOND XIA
Browse files

search sorting

parent 229b136a
......@@ -118,23 +118,48 @@ public class ClientApplication {
public static void search(String type, String keywords) {
String searchQueryString = "";
String sort = "";
boolean exitLoop = false;
while (!exitLoop) {
System.out.println("Type \"t\" to sort by title. Type \"p\" to sort by popularity. Press enter to sort default.");
sort = input.nextLine();
if (!sort.equals("t") && !sort.equals("p")) {
if (sort.equals("")) {
exitLoop = true;
} else {
System.out.println("Invalid command.");
}
} else {
exitLoop = true;
}
}
String sortString = "";
switch (sort) {
case "t":
sortString = "order by title";
break;
case "p":
sortString = "order by totalRating desc";
break;
default: break;
}
switch (type) {
case "movie":
searchQueryString = "select title, releaseDate, description from Movies where title like '%%%s%%' limit 10";
searchQueryString = "select title, releaseDate, description from Movies where title like '%%%s%%' %s limit 10";
break;
case "genre":
searchQueryString = "select title, releaseDate, genre, description from ImdbMovies where genre like '%%%s%%' limit 10";
searchQueryString = "select title, releaseDate, genre, description from Movies inner join GenresInMovies using (movieID) where genre like '%%%s%%' %s limit 10";
break;
case "person":
searchQueryString = "select title, releaseDate, actors, description from ImdbMovies where actors like '%%%s%%' limit 10";
searchQueryString = "select title, releaseDate, name, role, description from Movies inner join (People inner join PeopleInMovies using (personID)) using (movieID) where name like '%%%s%%' %s limit 10";
break;
default: break;
}
try {
Statement st = c.createStatement();
String query = String.format(searchQueryString, keywords);
String query = String.format(searchQueryString, keywords, sortString);
ResultSet rs = st.executeQuery(query);
printQueryResults(rs);
// Possible queries
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment