Commit a72ac469 authored by Arhan Banerjee's avatar Arhan Banerjee
Browse files

Updated SQL commands in search

parent 98214a3b
......@@ -183,59 +183,107 @@ def search():
search_command = input("What attribute would you like to search by? (Press 'help' for list of search commands or 'End search' to exit): ")
if(search_command == "help"):
print("\nRecipeID\nUserID\nRecipe Name\nMinutes\nTags\nCalories\nFat\nSugar\nSodium\nProtein\nSaturated Fat\nCarbs\nSteps Count\nIngredients\nIngredients Count\nRating\n")
print("\nRecipeID\nUserID\nRecipe Name\nMinutes\nTags\nCalories\nFat\nSugar\nSodium\nProtein\nSaturated Fat\nCarbs\nSteps Count\nIngredients\nIngredients Count\nRating\nUser Interactions\n")
elif(search_command == "Recipe Name"):
search_attribute = input("Enter part or full recipe name to search by: ")
sql_command = "SELECT * FROM recipes WHERE Name LIKE '%" + search_attribute + "%';"
print(sql_command)
# SQL code
elif(search_command == "Minutes"):
search_attribute = input("Enter max number of minutes taken for a recipe: ")
sql_command = "SELECT * FROM recipes WHERE Minutes <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Tags"):
search_attribute = input("Enter tags seperated by commas to search by: ")
tag_list = splitter(search_attribute, True)
print(tag_list)
#print(tag_list)
tag_list_string = "[" + ", ".join(tag_list) + "]"
sql_command = "WITH tagIds AS (SELECT tag_id FROM tags WHERE name IN " + tag_list_string + ") SELECT recipes.* FROM recipes INNER JOIN recipe_tags USING(recipe_id) INNER JOIN tagIds USING(tag_id);"
print(sql_command)
# SQL code
elif(search_command == "Calories"):
search_attribute = input("Enter max calorie count to search by: ")
sql_command = "SELECT * FROM recipes WHERE calories <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Fat"):
search_attribute = input("Enter max fat count to search by: ")
sql_command = "SELECT * FROM recipes WHERE fat <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Sugar"):
search_attribute = input("Enter max sugar count to search by: ")
sql_command = "SELECT * FROM recipes WHERE sugar <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Sodium"):
search_attribute = input("Enter max sodium count to search by: ")
sql_command = "SELECT * FROM recipes WHERE sodium <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Protein"):
search_attribute = input("Enter max protein count to search by: ")
sql_command = "SELECT * FROM recipes WHERE protein <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Saturated Fat"):
search_attribute = input("Enter max saturated fat to search by: ")
sql_command = "SELECT * FROM recipes WHERE saturated_fat <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Carbs"):
search_attribute = input("Enter max carbohydrates count to search by: ")
sql_command = "SELECT * FROM recipes WHERE carbohydrates <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Steps Count"):
search_attribute = input("Enter max number of steps to search by: ")
sql_command = "SELECT * FROM recipes WHERE n_steps <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Ingredients"):
search_attribute = input("Enter ingredients seperated by commas to search by: ")
ingredient_list = splitter(search_attribute, False)
print(ingredient_list)
#print(ingredient_list)
ingredients_list_string = "[" + ", ".join(ingredient_list) + "]"
sql_command = "WITH ingredientIds AS ( SELECT ingredient_id FROM ingredients WHERE name IN " + ingredients_list_string + " ) SELECT recipes.* FROM recipes INNER JOIN recipe_ingredients USING(recipe_id) INNER JOIN ingredientIds USING(ingredient_id);"
print(sql_command)
# SQL code
elif(search_command == "Ingredients Count"):
search_attribute = input("Enter max number of ingredients to search by: ")
sql_command = "SELECT * FROM recipes WHERE n_ingredients <= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "Rating"):
elif(search_command == "Minimum Rating"):
search_attribute = input("Enter minimum rating to search by: ")
sql_command = "SELECT DISTINCT recipes.* FROM recipes INNER JOIN interactions USING(recipe_id) WHERE rating >= " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "RecipeID"):
search_attribute = input("Enter a RecipeID to search by: ")
sql_command = "SELECT * FROM recipes WHERE recipe_id = " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "UserID"):
search_attribute = input("Enter an UserID to search by: ")
search_attribute = input("Enter a UserID to search by: ")
sql_command = "SELECT * FROM recipes WHERE user_id = " + search_attribute + ";"
print(sql_command)
# SQL code
elif(search_command == "User Interactions"):
search_attribute = input("Enter a RecipeID to search by: ")
search_attribute1 = input("Enter a UserID to search by: ")
sql_command = "SELECT * FROM recipes WHERE recipe_id = " + search_attribute + " AND user_id = " + search_attribute1 + ";"
print(sql_command)
#SQL code
elif(search_command == "End search"):
continue
else:
......
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