Complete term

This commit is contained in:
Daoud Clarke 2021-03-18 21:48:35 +00:00
parent 257ea7a397
commit 2eb6afc3fe

20
app.py
View file

@ -19,9 +19,29 @@ def search(s: str):
return RedirectResponse(url)
def complete_term(term):
con = sqlite3.connect(INDEX_PATH)
query = f"""
SELECT term, count(*)
FROM terms
WHERE term LIKE (? || '%')
LIMIT 1
"""
result = con.execute(query, (term,))
completed = result.fetchone()
print("Completed", completed)
if len(completed) > 0:
return completed[0]
return None
@app.get("/complete")
def complete(q: str):
terms = [x.lower() for x in q.split()]
completed = complete_term(terms[-1])
terms = terms[:-1] + [completed]
con = sqlite3.connect(INDEX_PATH)
in_part = ','.join('?'*len(terms))
query = f"""