summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/bg/js/database.js9
-rw-r--r--ext/bg/js/search.js9
-rw-r--r--ext/bg/js/translator.js27
3 files changed, 36 insertions, 9 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index b6cf9063..9b560f78 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -130,7 +130,7 @@ class Database {
await Promise.all(promises);
}
- async findTermsBulk(termList, titles) {
+ async findTermsBulk(termList, titles, wildcard) {
this.validate();
const promises = [];
@@ -149,10 +149,11 @@ class Database {
const dbIndex2 = dbTerms.index('reading');
for (let i = 0; i < termList.length; ++i) {
- const only = IDBKeyRange.only(termList[i]);
+ const term = termList[i];
+ const query = wildcard ? IDBKeyRange.bound(term, `${term}\uffff`, false, false) : IDBKeyRange.only(term);
promises.push(
- Database.getAll(dbIndex1, only, i, processRow),
- Database.getAll(dbIndex2, only, i, processRow)
+ Database.getAll(dbIndex1, query, i, processRow),
+ Database.getAll(dbIndex2, query, i, processRow)
);
}
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index abd40640..aa56d1a6 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -203,11 +203,18 @@ class DisplaySearch extends Display {
async onSearchQueryUpdated(query, animate) {
try {
+ const details = {};
+ const match = /[\*\uff0a]+$/.exec(query);
+ if (match !== null) {
+ details.wildcard = true;
+ query = query.substr(0, query.length - match[0].length);
+ }
+
const valid = (query.length > 0);
this.setIntroVisible(!valid, animate);
this.updateSearchButton();
if (valid) {
- const {definitions} = await apiTermsFind(query, {}, this.optionsContext);
+ const {definitions} = await apiTermsFind(query, details, this.optionsContext);
this.setContentTerms(definitions, {
focus: false,
sentence: null,
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index dac53f93..583d6e31 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -227,9 +227,12 @@ class Translator {
}
}
- const textHiragana = jpKatakanaToHiragana(text);
const titles = Object.keys(dictionaries);
- const deinflections = await this.findTermDeinflections(text, textHiragana, titles);
+ const deinflections = (
+ details.wildcard ?
+ await this.findTermWildcard(text, titles) :
+ await this.findTermDeinflections(text, titles)
+ );
let definitions = [];
for (const deinflection of deinflections) {
@@ -265,7 +268,23 @@ class Translator {
return [definitions, length];
}
- async findTermDeinflections(text, text2, titles) {
+ async findTermWildcard(text, titles) {
+ const definitions = await this.database.findTermsBulk([text], titles, true);
+ if (definitions.length === 0) {
+ return [];
+ }
+
+ return [{
+ source: text,
+ term: text,
+ rules: 0,
+ definitions,
+ reasons: []
+ }];
+ }
+
+ async findTermDeinflections(text, titles) {
+ const text2 = jpKatakanaToHiragana(text);
const deinflections = (text === text2 ? this.getDeinflections(text) : this.getDeinflections2(text, text2));
if (deinflections.length === 0) {
@@ -289,7 +308,7 @@ class Translator {
deinflectionArray.push(deinflection);
}
- const definitions = await this.database.findTermsBulk(uniqueDeinflectionTerms, titles);
+ const definitions = await this.database.findTermsBulk(uniqueDeinflectionTerms, titles, false);
for (const definition of definitions) {
const definitionRules = Deinflector.rulesToRuleFlags(definition.rules);