diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-19 12:24:38 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-19 12:28:33 -0400 |
commit | 4446cbeabb28931a2c0777ae44dde70ec6aa8e9a (patch) | |
tree | df5f9216b4f91677225f39d0c28b82b4a506ff72 /ext/bg/js | |
parent | 96f37fd9dcce1d8bfdaebe2f949c7732eb4c746a (diff) |
Create getMergedSecondarySearchResults
Diffstat (limited to 'ext/bg/js')
-rw-r--r-- | ext/bg/js/translator.js | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 1e6a2492..66653f4b 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -69,6 +69,32 @@ class Translator { return {sequencedDefinitions, defaultDefinitions}; } + async getMergedSecondarySearchResults(text, expressionsMap, secondarySearchTitles) { + const secondarySearchResults = []; + if (secondarySearchTitles.length === 0) { + return secondarySearchResults; + } + + for (const expression of expressionsMap.keys()) { + 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); + } + } + } + + return secondarySearchResults; + } + async getMergedDefinition(text, dictionaries, sequencedDefinition, defaultDefinitions, secondarySearchTitles, mergedByTermIndices) { const result = sequencedDefinition.definitions; const rawDefinitionsBySequence = sequencedDefinition.rawDefinitions; @@ -82,26 +108,7 @@ class Translator { } const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence); - - const secondarySearchResults = []; - if (secondarySearchTitles.length > 0) { - for (const expression of result.expressions.keys()) { - if (expression === text) { - continue; - } - - for (const reading of result.expressions.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); - } - } - } - } + const secondarySearchResults = await this.getMergedSecondarySearchResults(text, result.expressions, secondarySearchTitles); dictTermsMergeByGloss(result, defaultDefinitions.concat(secondarySearchResults), definitionsByGloss, mergedByTermIndices); |