aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) {