diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-06-19 21:43:18 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-06-19 21:43:18 +1000 |
| commit | ee65f5e2e0e22748193457c3ccc121dec7eaf05e (patch) | |
| tree | 27d203c9778838a88e41b1ae000b4b915474c661 /backend | |
| parent | 6ff4615cf8734eec2422a573b6e96b9db1f322f2 (diff) | |
Fix search-result-repeats bug
Diffstat (limited to 'backend')
| -rwxr-xr-x | backend/server.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/backend/server.py b/backend/server.py index d63b928..53b0814 100755 --- a/backend/server.py +++ b/backend/server.py @@ -103,14 +103,19 @@ def lookupName(name, useReducedTree): 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 + foundNames = {n["name"] for n in temp} 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}) + for (altName,) in cur.execute(query1, ("%" + name + "%", newLim)): + if altName not in foundNames: + temp.append({"name": altName, "canonicalName": None}) + foundNames.add(altName) 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]}) + for (altName, cName) in cur.execute(query2, ("%" + name + "%", SEARCH_SUGG_LIMIT + 1)): + if altName not in foundNames: + temp.append({"name": altName, "canonicalName": cName}) + foundNames.add(altName) # temp.sort(key=lambda x: x["name"]) temp.sort(key=lambda x: len(x["name"])) |
