Change secondarySearchTitles to secondarySearchDictionaries

This commit is contained in:
toasted-nutbread 2020-02-15 15:25:22 -05:00
parent b6718dc4a4
commit 5e8b408a23
2 changed files with 14 additions and 8 deletions

View File

@ -26,7 +26,8 @@ function dictEnabledSet(options) {
const dictionary = optionsDictionaries[title]; const dictionary = optionsDictionaries[title];
if (!dictionary.enabled) { continue; } if (!dictionary.enabled) { continue; }
enabledDictionaryMap.set(title, { enabledDictionaryMap.set(title, {
priority: dictionary.priority || 0 priority: dictionary.priority || 0,
allowSecondarySearches: !!dictionary.allowSecondarySearches
}); });
} }
return enabledDictionaryMap; return enabledDictionaryMap;

View File

@ -70,8 +70,8 @@ class Translator {
return {sequencedDefinitions, defaultDefinitions}; return {sequencedDefinitions, defaultDefinitions};
} }
async getMergedSecondarySearchResults(text, expressionsMap, secondarySearchTitles) { async getMergedSecondarySearchResults(text, expressionsMap, secondarySearchDictionaries) {
if (secondarySearchTitles.length === 0) { if (secondarySearchDictionaries.length === 0) {
return []; return [];
} }
@ -85,7 +85,7 @@ class Translator {
} }
} }
const definitions = await this.database.findTermsExactBulk(expressionList, readingList, new Set(secondarySearchTitles)); const definitions = await this.database.findTermsExactBulk(expressionList, readingList, secondarySearchDictionaries);
for (const definition of definitions) { for (const definition of definitions) {
const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary); const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
definitionTags.push(dictTagBuildSource(definition.dictionary)); definitionTags.push(dictTagBuildSource(definition.dictionary));
@ -101,7 +101,7 @@ class Translator {
return definitions; return definitions;
} }
async getMergedDefinition(text, dictionaries, sequencedDefinition, defaultDefinitions, secondarySearchTitles, mergedByTermIndices) { async getMergedDefinition(text, dictionaries, sequencedDefinition, defaultDefinitions, secondarySearchDictionaries, mergedByTermIndices) {
const result = sequencedDefinition.definitions; const result = sequencedDefinition.definitions;
const rawDefinitionsBySequence = sequencedDefinition.rawDefinitions; const rawDefinitionsBySequence = sequencedDefinition.rawDefinitions;
@ -114,7 +114,7 @@ class Translator {
} }
const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence); const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence);
const secondarySearchResults = await this.getMergedSecondarySearchResults(text, result.expressions, secondarySearchTitles); const secondarySearchResults = await this.getMergedSecondarySearchResults(text, result.expressions, secondarySearchDictionaries);
dictTermsMergeByGloss(result, defaultDefinitions.concat(secondarySearchResults), definitionsByGloss, mergedByTermIndices); dictTermsMergeByGloss(result, defaultDefinitions.concat(secondarySearchResults), definitionsByGloss, mergedByTermIndices);
@ -174,7 +174,12 @@ class Translator {
async findTermsMerged(text, details, options) { async findTermsMerged(text, details, options) {
const dictionaries = dictEnabledSet(options); const dictionaries = dictEnabledSet(options);
const secondarySearchTitles = Object.keys(options.dictionaries).filter((dict) => options.dictionaries[dict].allowSecondarySearches); const secondarySearchDictionaries = new Map();
for (const [title, dictionary] of dictionaries.entries()) {
if (!dictionary.allowSecondarySearches) { continue; }
secondarySearchDictionaries.set(title, dictionary);
}
const [definitions, length] = await this.findTermsInternal(text, dictionaries, details, options); const [definitions, length] = await this.findTermsInternal(text, dictionaries, details, options);
const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary); const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary);
const definitionsMerged = []; const definitionsMerged = [];
@ -186,7 +191,7 @@ class Translator {
dictionaries, dictionaries,
sequencedDefinition, sequencedDefinition,
defaultDefinitions, defaultDefinitions,
secondarySearchTitles, secondarySearchDictionaries,
mergedByTermIndices mergedByTermIndices
); );
definitionsMerged.push(result); definitionsMerged.push(result);