Commit 42388771 authored by Daniel Kim's avatar Daniel Kim
Browse files

done search ig

parent e8038beb
......@@ -47,6 +47,7 @@ public class ClientApplication {
columnMapper.put("dateOfDeath", "Date of Death");
columnMapper.put("placeOfDeath", "Place of Death");
columnMapper.put("reasonOfDeath", "Reason of Death");
columnMapper.put("role", "Role");
String command = "";
while (!exitLoop) {
......@@ -235,7 +236,7 @@ public class ClientApplication {
while (rs.next()) {
setItem++;
if (setItem == row) {
for (int i = 1; i <= columnsNumber; i++) {
for (int i = 2; i <= columnsNumber; i++) {
if (columnMapper.containsKey(rsmd.getColumnName(i))) {
System.out.print(columnMapper.get(rsmd.getColumnName(i)) + ": ");
}
......@@ -263,11 +264,12 @@ public class ClientApplication {
Statement st = c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String query = "";
String searchMovieQueryString = "select "
+ "movieID, "
+ "title, "
+ "originalTitle, "
+ "group_concat(genre separator ', ') AS genre, "
+ "year, "
+ "releaseDate, "
+ "substring_index(releaseDate, ' ', 1) as releaseDate, "
+ "duration, "
+ "description, "
+ "averageRating, "
......@@ -277,24 +279,22 @@ public class ClientApplication {
+ "incomeWorldwide, "
+ "budget, "
+ "productionCompany, "
+ "language, "
+ "userID, "
+ "comment "
+ "language "
+ "from "
+ "Movies left outer join Income using (movieID) "
+ "left outer join Budget using (movieID) "
+ "left outer join ProductionCompaniesInMovies using (movieID) "
+ "left outer join LanguagesInMovies using (movieID) "
+ "left outer join GenresInMovies using (movieID) "
+ "left outer join Reviews using (movieID) where ";
+ "where ";
String searchPersonQueryString = "select name, "
String searchPersonQueryString = "select personID, name, "
+ "birthName, "
+ "height, "
+ "bio, "
+ "birthDetails, "
+ "dateOfBirth, "
+ "dateOfDeath, "
+ "substring_index(dateOfBirth, ' ', 1) as dateOfBirth, "
+ "substring_index(dateOfDeath, ' ', 1) as dateOfDeath, "
+ "placeOfDeath, "
+ "reasonOfDeath "
+ "from People "
......@@ -334,7 +334,7 @@ public class ClientApplication {
basicAttributes.add("title");
basicAttributes.add("genre");
basicAttributes.add("releaseDate");
basicAttributes.add("description");
basicAttributes.add("averageRating");
basicAttributes.add("totalRating");
searchQueryString = searchMovieQueryString + "title like '%%%s%%' group by movieID %s limit 10";
......@@ -357,12 +357,29 @@ public class ClientApplication {
}
else {
rs.beforeFirst();
int setItem = 0;
printQueryResults(rs, Integer.parseInt(command));
rs.beforeFirst();
while (rs.next()) {
setItem++;
if (setItem == Integer.parseInt(command)) {
String movieID = rs.getString(1);
searchQueryString = String.format("select * from Reviews where movieID = '%s'", movieID);
ResultSet rs2 = st.executeQuery(searchQueryString);
System.out.println("User reviews for the movie");
HashSet<String> userReviewSet = new HashSet<String>();
userReviewSet.add("userID");
userReviewSet.add("comment");
printQueryResults(rs2, userReviewSet);
break;
}
}
exitLoop2 = true;
}
}
basicAttributes.clear();
break;
case "genre":
while (!exitLoop) {
......@@ -393,14 +410,14 @@ public class ClientApplication {
basicAttributes.add("title");
basicAttributes.add("genre");
basicAttributes.add("releaseDate");
basicAttributes.add("description");
basicAttributes.add("averageRating");
basicAttributes.add("totalRating");
searchQueryString = "select "
+ "movieID, "
+ "title, "
+ "group_concat(genre separator ', ') AS genre, "
+ "releaseDate, "
+ "substring_index(releaseDate, ' ', 1) as releaseDate, "
+ "description, "
+ "totalRating "
+ "from Movies left outer join GenresInMovies using (movieID) where genre like '%%%s%%' group by movieID %s limit 10";
......@@ -472,7 +489,7 @@ public class ClientApplication {
basicAttributes.add("birthDetails");
basicAttributes.add("dateOfBirth");
searchQueryString = "select personID, name, birthName, height, bio, birthDetails, dateOfBirth, dateOfDeath, placeOfDeath, reasonOfDeath from People left outer join DeadPeople using (personID) left outer join PeopleInMovies using (personID) left outer join Movies using (movieID) where name like '%%%s%%' group by personID %s limit 10";
searchQueryString = "select personID, name, birthName, height, bio, birthDetails, substring_index(dateOfBirth, ' ', 1) as dateOfBirth, substring_index(dateOfDeath, ' ', 1) as dateOfDeath, placeOfDeath, reasonOfDeath from People left outer join DeadPeople using (personID) left outer join PeopleInMovies using (personID) left outer join Movies using (movieID) where name like '%%%s%%' group by personID %s limit 10";
query = String.format(searchQueryString, keywords, sortString);
rs = st.executeQuery(query);
numResults = printQueryResults(rs, basicAttributes);
......@@ -498,9 +515,19 @@ public class ClientApplication {
String personID = rs.getString(1);
// searchQueryString = searchPersonQueryString;
searchQueryString = String.format(searchPersonQueryString, personID);
System.out.println(searchQueryString);
ResultSet rs2 = st.executeQuery(searchQueryString);
printQueryResults(rs2, 1);
searchQueryString = String.format("select * from PeopleInMovies left outer join movies using (movieID) where personID = '%s'", personID);
ResultSet rs3 = st.executeQuery(searchQueryString);
System.out.println("Related movies");
HashSet<String> peopleInMoviesSet = new HashSet<String>();
peopleInMoviesSet.add("role");
peopleInMoviesSet.add("title");
peopleInMoviesSet.add("year");
printQueryResults(rs3, peopleInMoviesSet);
break;
}
}
......@@ -516,6 +543,7 @@ public class ClientApplication {
} catch (Exception e) {
System.out.println(e);
}
System.out.println();
}
public static void addFavourite(String entity) {
......@@ -774,8 +802,8 @@ public class ClientApplication {
String server, pwd, db;
// System.out.print("Enter the SQL server to connect to: ");
// server = input.nextLine();
server = "127.0.0.1:3306";
// server = "marmoset03.shoshin.uwaterloo.ca";
// server = "127.0.0.1:3306";
server = "marmoset03.shoshin.uwaterloo.ca";
System.out.print("Enter username for the SQL server: ");
User = input.nextLine();
pwd = new String(System.console().readPassword("Enter password for the SQL server: "));
......
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