This commit is contained in:
toasted-nutbread 2020-02-15 12:45:18 -05:00
parent cae8ed2767
commit bc94970a46

View File

@ -123,7 +123,7 @@ function dictTermsCompressTags(definitions) {
} }
function dictTermsGroup(definitions, dictionaries) { function dictTermsGroup(definitions, dictionaries) {
const groups = {}; const groups = new Map();
for (const definition of definitions) { for (const definition of definitions) {
const key = [definition.source, definition.expression]; const key = [definition.source, definition.expression];
key.push(...definition.reasons); key.push(...definition.reasons);
@ -132,26 +132,27 @@ function dictTermsGroup(definitions, dictionaries) {
} }
const keyString = key.toString(); const keyString = key.toString();
if (hasOwn(groups, keyString)) { let groupDefinitions = groups.get(keyString);
groups[keyString].push(definition); if (typeof groupDefinitions === 'undefined') {
} else { groupDefinitions = [];
groups[keyString] = [definition]; groups.set(keyString, groupDefinitions);
} }
groupDefinitions.push(definition);
} }
const results = []; const results = [];
for (const key in groups) { for (const groupDefinitions of groups.values()) {
const groupDefs = groups[key]; const firstDef = groupDefinitions[0];
const firstDef = groupDefs[0]; dictTermsSort(groupDefinitions, dictionaries);
dictTermsSort(groupDefs, dictionaries);
results.push({ results.push({
definitions: groupDefs, definitions: groupDefinitions,
expression: firstDef.expression, expression: firstDef.expression,
reading: firstDef.reading, reading: firstDef.reading,
furiganaSegments: firstDef.furiganaSegments, furiganaSegments: firstDef.furiganaSegments,
reasons: firstDef.reasons, reasons: firstDef.reasons,
termTags: firstDef.termTags, termTags: firstDef.termTags,
score: groupDefs.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER), score: groupDefinitions.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER),
source: firstDef.source source: firstDef.source
}); });
} }