fix(infra): better search result (#7774)

This commit is contained in:
EYHN
2024-08-07 09:16:43 +00:00
parent 2f0e39b702
commit d968cfe425
6 changed files with 85 additions and 74 deletions

View File

@@ -244,9 +244,12 @@ export class FullTextInvertedIndex implements InvertedIndex {
// normalize score
const maxScore = submatched.reduce((acc, s) => Math.max(acc, s.score), 0);
const minScore = submatched.reduce((acc, s) => Math.min(acc, s.score), 1);
const minScore = submatched.reduce((acc, s) => Math.min(acc, s.score), 0);
for (const { nid, score, position } of submatched) {
const normalizedScore = (score - minScore) / (maxScore - minScore);
const normalizedScore =
maxScore === minScore
? score
: (score - minScore) / (maxScore - minScore);
const match = matched.get(nid) || {
score: [] as number[],
positions: new Map(),