From 97de7883a388099d5f0ff235c678e1f01c6858e2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 19 Oct 2019 12:42:26 -0400 Subject: [PATCH] Update getMergedSecondarySearchResults to use findTermsExactBulk --- ext/bg/js/translator.js | 35 ++++++++++++++++++++--------------- 1 file 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) {