aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbackend/data/genOtolData.py1
-rwxr-xr-xbackend/server.py26
-rw-r--r--src/components/SearchModal.vue12
3 files changed, 27 insertions, 12 deletions
diff --git a/backend/data/genOtolData.py b/backend/data/genOtolData.py
index 2ae154d..d1567d3 100755
--- a/backend/data/genOtolData.py
+++ b/backend/data/genOtolData.py
@@ -210,6 +210,7 @@ print("Creating nodes and edges tables")
dbCon = sqlite3.connect(dbFile)
dbCur = dbCon.cursor()
dbCur.execute("CREATE TABLE nodes (name TEXT PRIMARY KEY, tips INT)")
+dbCur.execute("CREATE INDEX nodes_idx_nc ON nodes(name COLLATE NOCASE)")
dbCur.execute("CREATE TABLE edges (node TEXT, child TEXT, p_support INT, PRIMARY KEY (node, child))")
dbCur.execute("CREATE INDEX edges_child_idx ON edges(child)")
for node in nodeMap.values():
diff --git a/backend/server.py b/backend/server.py
index 08b6f57..54e4803 100755
--- a/backend/server.py
+++ b/backend/server.py
@@ -100,19 +100,31 @@ def lookupName(name, useReducedTree):
cur = dbCon.cursor()
results = []
hasMore = False
- query = None
+ # Get node names and alt-names
+ (query1, query2) = (None, None)
if not useReducedTree:
- query = "SELECT DISTINCT name, alt_name FROM names" \
+ query1 = "SELECT DISTINCT name FROM nodes" \
+ " WHERE name LIKE ? ORDER BY length(name) LIMIT ?"
+ query2 = "SELECT DISTINCT alt_name, name FROM names" \
" WHERE alt_name LIKE ? ORDER BY length(alt_name) LIMIT ?"
else:
- query = "SELECT DISTINCT names.name, alt_name FROM" \
+ query1 = "SELECT DISTINCT name FROM r_nodes" \
+ " WHERE name LIKE ? ORDER BY length(name) LIMIT ?"
+ query2 = "SELECT DISTINCT alt_name, names.name FROM" \
" names INNER JOIN r_nodes ON names.name = r_nodes.name" \
" WHERE alt_name LIKE ? ORDER BY length(alt_name) LIMIT ?"
- for row in cur.execute(query, (name + "%", SEARCH_SUGG_LIMIT)):
- results.append({"name": row[0], "altName": row[1]})
- if len(results) > SEARCH_SUGG_LIMIT:
+ # Join results, and get shortest
+ temp = []
+ for row in cur.execute(query1, (name + "%", SEARCH_SUGG_LIMIT + 1)):
+ 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]})
+ 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
- del results[-1]
+ #
return [results, hasMore]
def lookupNodeInfo(name, useReducedTree):
cur = dbCon.cursor()
diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue
index bc77a39..e78a2f1 100644
--- a/src/components/SearchModal.vue
+++ b/src/components/SearchModal.vue
@@ -5,7 +5,7 @@ import InfoIcon from './icon/InfoIcon.vue';
import {LayoutNode} from '../layout';
import type {TolMap} from '../tol';
-type SearchSugg = {name: string, altName: string}; // Represents a search string suggestion
+type SearchSugg = {name: string, canonicalName: string | null}; // Represents a search string suggestion
type SearchSuggResponse = [SearchSugg[], boolean]; // Holds search suggestions and an indication of if there was more
// Displays a search box, and sends search requests
@@ -46,7 +46,8 @@ export default defineComponent({
if (this.focusedSuggIdx == null){
this.resolveSearch((this.$refs.searchInput as HTMLInputElement).value.toLowerCase())
} else {
- this.resolveSearch(this.searchSuggs[this.focusedSuggIdx].name);
+ let sugg = this.searchSuggs[this.focusedSuggIdx]
+ this.resolveSearch(sugg.canonicalName || sugg.name);
}
},
resolveSearch(tolNodeName: string){
@@ -159,11 +160,12 @@ export default defineComponent({
<div class="absolute top-[100%] w-full">
<div v-for="(sugg, idx) of searchSuggs"
:style="{backgroundColor: idx == focusedSuggIdx ? '#a3a3a3' : 'white'}"
- class="border p-1 hover:underline hover:cursor-pointer" @click="resolveSearch(sugg.name)">
+ class="border p-1 hover:underline hover:cursor-pointer"
+ @click="resolveSearch(sugg.canonicalName || sugg.name)">
<info-icon :style="infoIconStyles"
class="float-right text-stone-500 hover:text-stone-900 hover:cursor-pointer"
- @click.stop="onInfoIconClick(sugg.name)"/>
- {{sugg.name == sugg.altName ? sugg.name : `${sugg.altName} (aka ${sugg.name})`}}
+ @click.stop="onInfoIconClick(sugg.canonicalName || sugg.name)"/>
+ {{sugg.canonicalName == null ? sugg.name : `${sugg.name} (aka ${sugg.canonicalName})`}}
</div>
<div v-if="searchHasMoreSuggs" class="bg-white px-1 text-center border">...</div>
</div>