diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-05-10 19:52:47 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-05-11 11:44:14 +1000 |
| commit | 6c61612564b9a30f747207c43729c3e7e8cbf0d3 (patch) | |
| tree | 3f0f3b4cc35162e73542942ef30da3f1a0bf6276 /backend/server.py | |
| parent | 3d895370a608d4f51726b74e2560dcf5f4ec43a8 (diff) | |
Use prefix-search with ranking-by-length
Diffstat (limited to 'backend/server.py')
| -rwxr-xr-x | backend/server.py | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/backend/server.py b/backend/server.py index 8e4a90f..e778c2f 100755 --- a/backend/server.py +++ b/backend/server.py @@ -24,8 +24,6 @@ if len(sys.argv) > 1: # Connect to db, and load spellfix extension dbCon = sqlite3.connect(dbFile) -dbCon.enable_load_extension(True) -dbCon.load_extension('./data/spellfix') # Some functions def lookupNodes(names): nodeObjs = {} @@ -95,22 +93,12 @@ def lookupName(name): cur = dbCon.cursor() results = [] hasMore = False - #for row in cur.execute( - # "SELECT DISTINCT name, alt_name FROM names WHERE alt_name LIKE ? LIMIT ?", - # (name, SEARCH_SUGG_LIMIT)): - # results.append({"name": row[0], "altName": row[1]}) - #for row in cur.execute( - # "SELECT DISTINCT names.name, names.alt_name, nodes.tips FROM" \ - # " names INNER JOIN nodes ON names.name = nodes.name " \ - # " WHERE alt_name LIKE ? ORDER BY nodes.tips DESC LIMIT ?", - # (name + "%", SEARCH_SUGG_LIMIT)): - # results.append({"name": row[0], "altName": row[1]}) for row in cur.execute( - "SELECT word, alt_name, name FROM" \ - " spellfix_alt_names INNER JOIN names ON alt_name = word" \ - " WHERE word MATCH ? LIMIT ?", - (name, SEARCH_SUGG_LIMIT)): - results.append({"name": row[2], "altName": row[0]}) + "SELECT DISTINCT names.name, names.alt_name, nodes.tips FROM" \ + " names INNER JOIN nodes ON names.name = nodes.name " \ + " WHERE alt_name LIKE ? ORDER BY length(alt_name) LIMIT ?", + (name + "%", SEARCH_SUGG_LIMIT)): + results.append({"name": row[0], "altName": row[1]}) if len(results) > SEARCH_SUGG_LIMIT: hasMore = True del results[-1] |
