diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2017-10-15 05:19:16 +0300 |
---|---|---|
committer | siikamiika <siikamiika@users.noreply.github.com> | 2017-10-15 05:19:16 +0300 |
commit | 03f7ca23e118c5ca804eef35cea05070e69779c7 (patch) | |
tree | f7f66ed1a2ad3b782af8cd84ffb5d3203b1928ac /ext/bg/js/translator.js | |
parent | 4203fda906a1b4a104187e54d256e5952d8ae55c (diff) |
merged mode: add secondary searches
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r-- | ext/bg/js/translator.js | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index c102f6a8..29bb857b 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -58,6 +58,7 @@ class Translator { async findTermsMerged(text, dictionaries, alphanumeric) { const options = await apiOptionsGet(); const mainDictionary = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].main).concat([''])[0]; + const secondarySearchTitles = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].allowSecondarySearches); const titles = Object.keys(dictionaries); const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric); @@ -74,7 +75,23 @@ class Translator { const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), mainDictionary); const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence); - dictTermsMergeByGloss(result, definitionsBySequence['-1'], definitionsByGloss, mergedByTermIndices); + + const secondarySearchResults = []; + if (secondarySearchTitles.length) { + 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)) { + secondarySearchResults.push(definition); + } + } + } + } + + dictTermsMergeByGloss(result, definitionsBySequence['-1'].concat(secondarySearchResults), definitionsByGloss, mergedByTermIndices); for (const gloss in definitionsByGloss) { const definition = definitionsByGloss[gloss]; @@ -88,7 +105,6 @@ class Translator { dictTermsSort(result.definitions, dictionaries); - // turn the Map()/Set() mess to [{expression: E1, reading: R1}, {...}] and tag popular/normal/rare instead of actual tags const expressions = []; for (const expression of result.expressions.keys()) { for (const reading of result.expressions.get(expression).keys()) { |