summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-19 12:42:26 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-19 12:42:26 -0400
commit97de7883a388099d5f0ff235c678e1f01c6858e2 (patch)
treeb3d86bb4acbeded32f88cfe0d92eb838723de74b /ext/bg
parent4446cbeabb28931a2c0777ae44dde70ec6aa8e9a (diff)
Update getMergedSecondarySearchResults to use findTermsExactBulk
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/translator.js35
1 files changed, 20 insertions, 15 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 66653f4b..fa445cbf 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -70,29 +70,34 @@ class Translator {
}
async getMergedSecondarySearchResults(text, expressionsMap, secondarySearchTitles) {
- const secondarySearchResults = [];
if (secondarySearchTitles.length === 0) {
- return secondarySearchResults;
+ return [];
}
+ const expressionList = [];
+ const readingList = [];
for (const expression of expressionsMap.keys()) {
- if (expression === text) {
- continue;
- }
-
+ if (expression === text) { continue; }
for (const reading of expressionsMap.get(expression).keys()) {
- for (const definition of await this.database.findTermsExact(expression, reading, secondarySearchTitles)) {
- const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
- definitionTags.push(dictTagBuildSource(definition.dictionary));
- definition.definitionTags = definitionTags;
- const termTags = await this.expandTags(definition.termTags, definition.dictionary);
- definition.termTags = termTags;
- secondarySearchResults.push(definition);
- }
+ expressionList.push(expression);
+ readingList.push(reading);
}
}
- return secondarySearchResults;
+ const definitions = await this.database.findTermsExactBulk(expressionList, readingList, secondarySearchTitles);
+ for (const definition of definitions) {
+ const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
+ definitionTags.push(dictTagBuildSource(definition.dictionary));
+ definition.definitionTags = definitionTags;
+ const termTags = await this.expandTags(definition.termTags, definition.dictionary);
+ definition.termTags = termTags;
+ }
+
+ if (definitions.length > 1) {
+ definitions.sort((a, b) => a.index - b.index);
+ }
+
+ return definitions;
}
async getMergedDefinition(text, dictionaries, sequencedDefinition, defaultDefinitions, secondarySearchTitles, mergedByTermIndices) {