Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chenww05 committed Sep 21, 2015
1 parent 3cc2a16 commit 4f67448
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions server/src/db/DBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -62,6 +63,7 @@ private Set<String> getCategories(String business_id) {
Set<String> set = new HashSet<>();
String[] categories = rs.getString("categories").split(",");
for (String category : categories) {
// ' Japanese ' -> 'Japanese'
set.add(category.trim());
}
return set;
Expand All @@ -79,6 +81,7 @@ private Set<String> getBusinessId(String category) {
return null;
}
Statement stmt = conn.createStatement();
// if category = Chinese, categories = Chinese, Korean, Japanese, it's a match
String sql = "SELECT business_id from RESTAURANTS WHERE categories LIKE '%"
+ category + "%'";
ResultSet rs = stmt.executeQuery(sql);
Expand Down Expand Up @@ -139,20 +142,23 @@ private JSONObject getRestaurantsById(String businessId) {

private Set<String> getMoreCategories(String category, int maxCount) {
Set<String> allCategories = new HashSet<>();
if (conn == null) {
return null;
}
Statement stmt;
try {
if (conn == null) {
return null;
}
Statement stmt = conn.createStatement();
stmt = conn.createStatement();

String sql = "SELECT second_id from USER_CATEGORY_HISTORY WHERE first_id=\""
+ category + "\" ORDER BY count DESC LIMIT " + maxCount;
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
String visited_restaurant = rs.getString("second_id");
allCategories.add(visited_restaurant);
}
} catch (Exception e) { /* report an error */
System.out.println(e.getMessage());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return allCategories;
}
Expand Down Expand Up @@ -184,6 +190,7 @@ public JSONArray RecommendRestaurants(String userId) {
Set<JSONObject> diff = new HashSet<>();
int count = 0;
for (String business_id : allRestaurants) {
// Perform filtering
if (!visitedRestaurants.contains(business_id)) {
diff.add(getRestaurantsById(business_id));
count++;
Expand Down Expand Up @@ -299,4 +306,9 @@ public JSONArray GetRestaurantsNearLoationViaYelpAPI(double lat, double lon) {
}
return null;
}

public static void main(String[] args) {
DBConnection conn = new DBConnection();
JSONArray array = conn.GetRestaurantsNearLoationViaYelpAPI(1.0, 2.0);
}
}
2 changes: 1 addition & 1 deletion server/src/db/DBImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class DBImport {

public static String parseString(String str) {
return str.replace("\"", "\\\"").replace("/", " or ");
return str.replace("\"", "\\\"").replace("/", " or ").replace("'", "");
}

public static String jsonArrayToString(JSONArray array) {
Expand Down

0 comments on commit 4f67448

Please sign in to comment.