else{
//to get recipes that have at least the listed ingredients, taking quantity into consideration
System.out.println("HI");
String temp = "LOL";
ArrayList <String>IDListBase = new ArrayList<String>();
String recNameQuery="SELECT recipe_id, recipe_name FROM recipe WHERE NOT EXISTS( SELECT * FROM ingredient_recipe WHERE NOT";
for (int j=0; j<extractedIngredientIDs.size(); j++){
recNameQuery+=" (ingredient_recipe.ingredient_id = ? and ingredient_recipe.quantity < ? )";
if (j<extractedIngredientIDs.size()-1){
recNameQuery+=" or";
}
}
recNameQuery+=")";
st=dbconn.prepareStatement(recNameQuery);
for (int j=0; j<extractedIngredientIDs.size(); j++){
st.setInt(j*2+1,extractedIngredientIDs.get(j));
st.setInt(j*2+2, extractedQuantities.get(j));
}
rs=st.executeQuery();
System.out.println("HI");
while(rs.next()) {
temp = rs.getString("recipe_ID");
if (!IDListBase.contains(temp))
IDListBase.add(temp);
}
for (String t : IDListBase){
System.out.println(t);
}
//to search based on a keyword in the description
String keyword = keywordSearchField.getText().toLowerCase();
System.out.println("HI");
if(!(keyword == null || keyword.equals(""))){
recNameQuery = "SELECT recipe_id, recipe_name FROM recipe WHERE LOWER(directions) LIKE '% ? %' ";
st.setString(1, keyword);
rs=st.executeQuery();
}
ArrayList<String> DirectionsList = new ArrayList<String>();
while(rs.next()) {
temp = rs.getString("recipe_ID");
DirectionsList.add(temp);
}
for (String q : DirectionsList){
System.out.println(q);
}
System.out.println("HI");
/*
recNameQuery="SELECT recipe_id, recipe_name FROM recipe WHERE directions='% ? %'";
st.setString(1, keyword);
rs=st.executeQuery();
*/
//to search by ethnicity
String ethnicity= ethnicityBox.getSelectedItem().toString().toLowerCase();
System.out.println(ethnicity);
recNameQuery="SELECT recipe_id, recipe_name FROM recipe WHERE LOWER(ethnicity) = ? ";
st.setString(1,ethnicity);
rs=st.executeQuery();
System.out.println("HI");
ArrayList<String> EthnicityList = new ArrayList<String>();
while(rs.next()) {
temp = rs.getString("recipe_ID");
EthnicityList.add(temp);
}
for (String v : EthnicityList){
System.out.println(v);
}
ArrayList<String> Result = new ArrayList<String>();
for(String s : IDListBase){
if(EthnicityList.size()==0){
if(DirectionsList.contains(s))Result.add(s);
}
else if (DirectionsList.size()==0){
Result.add(s);
}
else if(EthnicityList.contains(s)&&DirectionsList.contains(s)){
Result.add(s);
}
}
System.out.println("HI");
for (String a : Result){
System.out.println(a);
}
//to get recipes that have only the listed ingredients, taking quantity into consideration
} // end else (!anyParam)