From 6c61612564b9a30f747207c43729c3e7e8cbf0d3 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Tue, 10 May 2022 19:52:47 +1000 Subject: Use prefix-search with ranking-by-length --- backend/server.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'backend/server.py') 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] -- cgit v1.2.3