Complete term
This commit is contained in:
parent
257ea7a397
commit
2eb6afc3fe
1 changed files with 20 additions and 0 deletions
20
app.py
20
app.py
|
@ -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"""
|
||||
|
|
Loading…
Reference in a new issue