aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/database.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-23 21:48:24 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-07 14:34:35 -0500
commit16593408981d59e1bd3ad4de14071f45a8116d81 (patch)
treeec3d39929fd30c9ee1ab5bedb701d74760bf8f5b /ext/bg/js/database.js
parent7401408c39ee6097eb6c3e52635f87845832ce97 (diff)
Add support for prefix wildcards
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r--ext/bg/js/database.js30
1 files changed, 23 insertions, 7 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index a20d5f15..2d309f85 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -28,7 +28,7 @@ class Database {
}
try {
- this.db = await Database.open('dict', 4, (db, transaction, oldVersion) => {
+ this.db = await Database.open('dict', 5, (db, transaction, oldVersion) => {
Database.upgrade(db, transaction, oldVersion, [
{
version: 2,
@@ -76,6 +76,15 @@ class Database {
indices: ['dictionary', 'expression', 'reading', 'sequence']
}
}
+ },
+ {
+ version: 5,
+ stores: {
+ terms: {
+ primaryKey: {keyPath: 'id', autoIncrement: true},
+ indices: ['dictionary', 'expression', 'reading', 'sequence', 'expressionReverse', 'readingReverse']
+ }
+ }
}
]);
});
@@ -143,14 +152,17 @@ class Database {
}
};
+ const useWildcard = !!wildcard;
+ const prefixWildcard = wildcard === 'prefix';
+
const dbTransaction = this.db.transaction(['terms'], 'readonly');
const dbTerms = dbTransaction.objectStore('terms');
- const dbIndex1 = dbTerms.index('expression');
- const dbIndex2 = dbTerms.index('reading');
+ const dbIndex1 = dbTerms.index(prefixWildcard ? 'expressionReverse' : 'expression');
+ const dbIndex2 = dbTerms.index(prefixWildcard ? 'readingReverse' : 'reading');
for (let i = 0; i < termList.length; ++i) {
- const term = termList[i];
- const query = wildcard ? IDBKeyRange.bound(term, `${term}\uffff`, false, false) : IDBKeyRange.only(term);
+ const term = prefixWildcard ? stringReverse(termList[i]) : termList[i];
+ const query = useWildcard ? IDBKeyRange.bound(term, `${term}\uffff`, false, false) : IDBKeyRange.only(term);
promises.push(
Database.getAll(dbIndex1, query, i, processRow),
Database.getAll(dbIndex2, query, i, processRow)
@@ -377,7 +389,9 @@ class Database {
rules,
score,
glossary,
- dictionary: summary.title
+ dictionary: summary.title,
+ expressionReverse: stringReverse(expression),
+ readingReverse: stringReverse(reading)
});
}
} else {
@@ -391,7 +405,9 @@ class Database {
glossary,
sequence,
termTags,
- dictionary: summary.title
+ dictionary: summary.title,
+ expressionReverse: stringReverse(expression),
+ readingReverse: stringReverse(reading)
});
}
}