summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-19 12:24:38 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-19 12:28:33 -0400
commit4446cbeabb28931a2c0777ae44dde70ec6aa8e9a (patch)
treedf5f9216b4f91677225f39d0c28b82b4a506ff72 /ext/bg
parent96f37fd9dcce1d8bfdaebe2f949c7732eb4c746a (diff)
Create getMergedSecondarySearchResults
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/translator.js47
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);