mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-03 06:03:21 +03:00
feat(core): better search result (#7787)
This commit is contained in:
parent
c7aabd3a8d
commit
6ef5675be1
@ -179,8 +179,9 @@ export class FullTextInvertedIndex implements InvertedIndex {
|
|||||||
const matched = new Map<
|
const matched = new Map<
|
||||||
number,
|
number,
|
||||||
{
|
{
|
||||||
score: number[];
|
score: number;
|
||||||
positions: Map<number, [number, number][]>;
|
index: number;
|
||||||
|
ranges: [number, number][];
|
||||||
}
|
}
|
||||||
>();
|
>();
|
||||||
for (const token of queryTokens) {
|
for (const token of queryTokens) {
|
||||||
@ -250,27 +251,20 @@ export class FullTextInvertedIndex implements InvertedIndex {
|
|||||||
maxScore === minScore
|
maxScore === minScore
|
||||||
? score
|
? score
|
||||||
: (score - minScore) / (maxScore - minScore);
|
: (score - minScore) / (maxScore - minScore);
|
||||||
const match = matched.get(nid) || {
|
const match = matched.get(nid);
|
||||||
score: [] as number[],
|
if (!match || normalizedScore > match.score) {
|
||||||
positions: new Map(),
|
matched.set(nid, {
|
||||||
};
|
score: normalizedScore,
|
||||||
match.score.push(normalizedScore);
|
index: position.index,
|
||||||
const ranges = match.positions.get(position.index) || [];
|
ranges: position.ranges,
|
||||||
ranges.push(...position.ranges);
|
});
|
||||||
match.positions.set(position.index, ranges);
|
}
|
||||||
matched.set(nid, match);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const match = new Match();
|
const match = new Match();
|
||||||
for (const [nid, { score, positions }] of matched) {
|
for (const [nid, { score, index, ranges }] of matched) {
|
||||||
match.addScore(
|
match.addScore(nid, score);
|
||||||
nid,
|
match.addHighlighter(nid, this.fieldKey, index, ranges);
|
||||||
score.reduce((acc, s) => acc + s, 0)
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const [index, ranges] of positions) {
|
|
||||||
match.addHighlighter(nid, this.fieldKey, index, ranges);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user