summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/api.js2
-rw-r--r--ext/bg/js/translator.js33
2 files changed, 27 insertions, 8 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 5c1aebb6..9f65bb07 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -31,7 +31,7 @@ async function apiTermsFind(text) {
const searcher = options.general.groupResults ?
translator.findTermsGrouped.bind(translator) :
- translator.findTerms.bind(translator);
+ translator.findTermsSplit.bind(translator);
const {definitions, length} = await searcher(
text,
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 0ecae16b..19769536 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -37,8 +37,26 @@ class Translator {
}
async findTermsGrouped(text, dictionaries, alphanumeric) {
+ const titles = Object.keys(dictionaries);
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
- return {length, definitions: dictTermsGroup(definitions, dictionaries)};
+
+ const definitionsGrouped = dictTermsGroup(definitions, dictionaries);
+ for (const definition of definitionsGrouped) {
+ this.buildTermFrequencies(definition, titles);
+ }
+
+ return {length, definitions: definitionsGrouped};
+ }
+
+ async findTermsSplit(text, dictionaries, alphanumeric) {
+ const titles = Object.keys(dictionaries);
+ const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
+
+ for (const definition of definitions) {
+ this.buildTermFrequencies(definition, titles);
+ }
+
+ return {length, definitions};
}
async findTerms(text, dictionaries, alphanumeric) {
@@ -63,13 +81,7 @@ class Translator {
const tags = await this.buildTags(definition.tags, definition.dictionary);
tags.push(dictTagBuildSource(definition.dictionary));
- let frequencies = await this.database.findTermFreq(definition.expression, titles);
- if (frequencies.length === 0) {
- frequencies = await this.database.findTermFreq(definition.reading, titles);
- }
-
definitions.push({
- frequencies,
source: deinflection.source,
reasons: deinflection.reasons,
score: definition.score,
@@ -134,6 +146,13 @@ class Translator {
return definitions;
}
+ async buildTermFrequencies(definition, titles) {
+ definition.frequencies = await this.database.findTermFreq(definition.expression, titles);
+ if (definition.frequencies.length === 0) {
+ definition.frequencies = await this.database.findTermFreq(definition.reading, titles);
+ }
+ }
+
async buildTags(names, title) {
const results = [];
for (const name of names) {