diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-06-19 17:29:34 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-06-19 17:29:34 +1000 |
| commit | 46357d6e93278ea37cb448ba341effc38aa36840 (patch) | |
| tree | c3ce079dd3a29e2ecb490233ac1dbc55155ddb14 /backend/server.py | |
| parent | cd611fc89535357b227dbc21727534c6275a27f0 (diff) | |
Add fallback substring-search
Diffstat (limited to 'backend/server.py')
| -rwxr-xr-x | backend/server.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/backend/server.py b/backend/server.py index 576a239..d63b928 100755 --- a/backend/server.py +++ b/backend/server.py @@ -102,12 +102,21 @@ def lookupName(name, useReducedTree): temp.append({"name": row[0], "canonicalName": None}) for row in cur.execute(query2, (name + "%", SEARCH_SUGG_LIMIT + 1)): temp.append({"name": row[0], "canonicalName": row[1]}) + # If insufficient results, try substring-search + if len(temp) < SEARCH_SUGG_LIMIT: + newLim = SEARCH_SUGG_LIMIT + 1 - len(temp) + for row in cur.execute(query1, ("%" + name + "%", newLim)): + temp.append({"name": row[0], "canonicalName": None}) + if len(temp) < SEARCH_SUGG_LIMIT: + newLim = SEARCH_SUGG_LIMIT + 1 - len(temp) + for row in cur.execute(query2, ("%" + name + "%", SEARCH_SUGG_LIMIT + 1)): + temp.append({"name": row[0], "canonicalName": row[1]}) + # temp.sort(key=lambda x: x["name"]) temp.sort(key=lambda x: len(x["name"])) results = temp[:SEARCH_SUGG_LIMIT] if len(temp) > SEARCH_SUGG_LIMIT: hasMore = True - # return [results, hasMore] def lookupNodeInfo(name, useReducedTree): cur = dbCon.cursor() |
