diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-07-12 02:53:24 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-07-12 02:53:24 +1000 |
| commit | de6ffa836d7e35730c44ac244345d3368e4bbbe0 (patch) | |
| tree | 57a6bbbc5f594978f1c07f743a6697c157f14e6f /backend | |
| parent | 6071e0b9d097e94a303662d28b8f46d2122037c4 (diff) | |
Fix search-suggestions not prioritising prefix-matches
Diffstat (limited to 'backend')
| -rwxr-xr-x | backend/tilo.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/backend/tilo.py b/backend/tilo.py index 89cc867..8bbe528 100755 --- a/backend/tilo.py +++ b/backend/tilo.py @@ -157,21 +157,25 @@ def lookupSuggs(searchStr, suggLimit, tree, dbCur): suggs.append(SearchSugg(altName, nodeName)) # If insufficient results, try substring-search foundNames = {n.name for n in suggs} + suggs2 = [] if len(suggs) < suggLimit: newLim = suggLimit + 1 - len(suggs) for (nodeName,) in dbCur.execute(query1, ("%" + searchStr + "%", newLim)): if nodeName not in foundNames: - suggs.append(SearchSugg(nodeName)) + suggs2.append(SearchSugg(nodeName)) foundNames.add(nodeName) - if len(suggs) < suggLimit: - newLim = suggLimit + 1 - len(suggs) + if len(suggs) + len(suggs2) < suggLimit: + newLim = suggLimit + 1 - len(suggs) - len(suggs2) for (altName, nodeName) in dbCur.execute(query2, ("%" + searchStr + "%", suggLimit + 1)): if altName not in foundNames: - suggs.append(SearchSugg(altName, nodeName)) + suggs2.append(SearchSugg(altName, nodeName)) foundNames.add(altName) # Sort results suggs.sort(key=lambda x: x.name) suggs.sort(key=lambda x: len(x.name)) + suggs2.sort(key=lambda x: x.name) + suggs2.sort(key=lambda x: len(x.name)) + suggs.extend(suggs2) # Apply suggestion-quantity limit results = suggs[:suggLimit] if len(suggs) > suggLimit: |
