Skip to content

Commit

Permalink
Fix ranking bug affecting compound words
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw authored and cdxker committed Dec 16, 2024
1 parent 1fdbac3 commit 477a142
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ steps:
- step: In my browser, I evaluate {js}
js: |-
let val = await toolproof.querySelector("p");
toolproof.assert_eq(val.innerHTML, `weight:1/bal:512.14/loc:4`);
toolproof.assert_eq(val.innerHTML, `weight:1/bal:1024.29/loc:4`);
2 changes: 2 additions & 0 deletions pagefind_web/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,12 @@ impl SearchIndex {
// If the new word is weighted _lower_ than the working word,
// we want to use the lower value. (Lowest weight wins)
working_word.weight = next_word.weight;
working_word.length_bonus = next_word.length_bonus;
} else if next_word.weight == working_word.weight {
// If the new word is weighted the same,
// we want to combine them to boost matching both halves of a compound word
working_word.weight += next_word.weight;
working_word.length_bonus += next_word.length_bonus;
}
// We don't want to do anything if the new word is weighted higher
// (Lowest weight wins)
Expand Down

0 comments on commit 477a142

Please sign in to comment.