diff options
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/js/dictionary.js | 8 | ||||
-rw-r--r-- | ext/bg/js/translator.js | 19 |
2 files changed, 14 insertions, 13 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 50932735..fea5f3e5 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -229,7 +229,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) { definitionsByGloss[gloss] = { expression: new Set(), reading: new Set(), - definitionTags: new Set(), + definitionTags: [], glossary: definition.glossary, source: result.source, reasons: [], @@ -254,10 +254,8 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) { } for (const tag of definition.definitionTags) { - if (typeof tag === 'string') { - definitionsByGloss[gloss].definitionTags.add(tag); - } else if (tag.category && tag.category !== 'dictionary') { - definitionsByGloss[gloss].definitionTags.add(tag.name); + if (!definitionsByGloss[gloss].definitionTags.find(existingTag => existingTag.name === tag.name)) { + definitionsByGloss[gloss].definitionTags.push(tag); } } diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index e6790fbf..238af94d 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -73,6 +73,13 @@ class Translator { const result = definitionsBySequence[sequence]; const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), options.general.mainDictionary); + + for (const definition of rawDefinitionsBySequence) { + const tags = await this.expandTags(definition.definitionTags, definition.dictionary); + tags.push(dictTagBuildSource(definition.dictionary)); + definition.definitionTags = tags; + } + const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence); const secondarySearchResults = []; @@ -84,6 +91,9 @@ class Translator { for (const reading of result.expressions.get(expression).keys()) { for (const definition of await this.database.findTermsExact(expression, reading, secondarySearchTitles)) { + const tags = await this.expandTags(definition.definitionTags, definition.dictionary); + tags.push(dictTagBuildSource(definition.dictionary)); + definition.definitionTags = tags; secondarySearchResults.push(definition); } } @@ -94,11 +104,7 @@ class Translator { for (const gloss in definitionsByGloss) { const definition = definitionsByGloss[gloss]; - - const tags = await this.expandTags(definition.definitionTags, definition.dictionary); - tags.push(dictTagBuildSource(definition.dictionary)); - definition.definitionTags = dictTagsSort(tags); - + dictTagsSort(definition.definitionTags); result.definitions.push(definition); } @@ -289,9 +295,6 @@ class Translator { async expandTags(names, title) { const tags = []; for (const name of names) { - if (typeof name !== 'string') { - continue; - } const base = name.split(':')[0]; const meta = await this.database.findTagForTitle(base, title); |