mirror of
https://github.com/Sosokker/Packaged-Food-Explorer.git
synced 2025-12-18 20:54:05 +01:00
faster search/ add limit
This commit is contained in:
parent
66b503bfd0
commit
fb62600048
@ -39,12 +39,13 @@ class FoodSearch:
|
||||
|
||||
try:
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
cursor = conn.cursor()
|
||||
query = "SELECT * FROM food_data WHERE product_name LIKE ?"
|
||||
cursor.execute(query, (f"%{user_input}%",))
|
||||
results = cursor.fetchall()
|
||||
conn.execute("CREATE INDEX IF NOT EXISTS idx_product_name ON food_data(product_name)")
|
||||
|
||||
query = "SELECT * FROM food_data WHERE product_name LIKE ? LIMIT 100"
|
||||
user_input = f"%{user_input}%"
|
||||
results = conn.execute(query, (user_input,)).fetchall()
|
||||
|
||||
return results
|
||||
except sqlite3.Error as e:
|
||||
|
||||
print(f"Database error: {e}")
|
||||
return []
|
||||
Loading…
Reference in New Issue
Block a user