Skip to content

Commit 810382b

Browse files
committed
chore: deduplicate comparison logic
1 parent 12af917 commit 810382b

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

lib/features/search/search.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,16 @@ function createResultSorter(keys, keyWeights = {}) {
155155
for (let i = 0; i < keys.length; i++) {
156156
const key = keys[i];
157157

158-
const tokenComparison = compareTokens(
159-
resultA.tokens[key],
160-
resultB.tokens[key]
161-
);
162-
163-
if (tokenComparison !== 0) {
164-
comparison += tokenComparison * (keyWeights[key] ?? Math.pow(0.5, i));
165-
continue;
166-
}
167-
168-
const stringComparison = compareStrings(
158+
const resultComparison = compareTokens(
159+
resultA.tokens[ key ],
160+
resultB.tokens[ key ]
161+
) || compareStrings(
169162
resultA.item[ key ],
170163
resultB.item[ key ]
171164
);
172165

173-
if (stringComparison !== 0) {
174-
comparison += stringComparison * (keyWeights[key] ?? Math.pow(0.5, i));
175-
continue;
176-
}
166+
comparison += resultComparison * (keyWeights[key] ?? Math.pow(0.5, i));
167+
177168
}
178169

179170
return comparison;

0 commit comments

Comments
 (0)