Skip to content

Build your personal knowledge base with Trilium Notes

docs(search): describe the ranking shortlist as the approximation it is

Elian Doran78b64a3d41ff
diff --git a/packages/trilium-core/src/services/search/expressions/note_content_fulltext.ts b/packages/trilium-core/src/services/search/expressions/note_content_fulltext.ts
index 5386617d15..c433c34fea 100644
--- a/packages/trilium-core/src/services/search/expressions/note_content_fulltext.ts
+++ b/packages/trilium-core/src/services/search/expressions/note_content_fulltext.ts
@@ -549,7 +549,7 @@ class NoteContentFulltextExp extends Expression {
/**
* Fuzzy matches a single token against a single word, returning the word it matched so
- * callers can highlight it. The edit-distance bound is length-scaled (AUTO), so short
+ * callers can highlight it. The edit-distance bound is length-scaled, so short
* tokens do not produce false positives.
*/
private fuzzyMatchSingle(token: string, word: string): string | null {
diff --git a/packages/trilium-core/src/services/search/expressions/note_flat_text.ts b/packages/trilium-core/src/services/search/expressions/note_flat_text.ts
index 526aeb4c5b..9c63b359b4 100644
--- a/packages/trilium-core/src/services/search/expressions/note_flat_text.ts
+++ b/packages/trilium-core/src/services/search/expressions/note_flat_text.ts
@@ -268,8 +268,8 @@ class NoteFlatTextExp extends Expression {
return true;
}
- // Fuzzy fallback only if enabled and the token is long enough to allow any
- // edit distance under the length-scaled (AUTO) rule (i.e. >= 3 characters).
+ // Fuzzy fallback only if enabled and the token is long enough to be allowed any edit
+ // distance under the length-scaled rule, which starts at four characters.
if (searchContext?.enableFuzzyMatching && getAutoMaxEditDistance(token.length) > 0) {
const matchedWord = fuzzyMatchWordWithResult(token, text);
if (matchedWord) {
diff --git a/packages/trilium-core/src/services/search/search_context.ts b/packages/trilium-core/src/services/search/search_context.ts
index 81c45954d1..f1ea3a9741 100644
--- a/packages/trilium-core/src/services/search/search_context.ts
+++ b/packages/trilium-core/src/services/search/search_context.ts
@@ -23,7 +23,7 @@ class SearchContext {
debugInfo: {} | null;
fuzzyAttributeSearch: boolean;
enableFuzzyMatching: boolean; // Controls whether fuzzy matching is enabled for this search phase
- /** When true, skip the two-phase fuzzy fallback and use the single-token fast path. */
+ /** When true, a single-token flat-text search resolves each match's best note path directly. */
autocomplete: boolean;
rankInTwoPasses: boolean;
highlightedTokens: string[];
diff --git a/packages/trilium-core/src/services/search/search_result.ts b/packages/trilium-core/src/services/search/search_result.ts
index ae73cd3345..2382d48c07 100644
--- a/packages/trilium-core/src/services/search/search_result.ts
+++ b/packages/trilium-core/src/services/search/search_result.ts
@@ -256,7 +256,7 @@ class SearchResult {
normalizedToken.length >= FUZZY_SEARCH_CONFIG.MIN_FUZZY_TOKEN_LENGTH &&
this.fuzzyScore < SCORE_WEIGHTS.MAX_TOTAL_FUZZY_SCORE) {
// Only compute edit distance when fuzzy matching is enabled.
- // Cap the per-chunk distance with the length-scaled (AUTO) bound
+ // Cap the per-chunk distance with the length-scaled bound
// so short tokens can't fuzzy-match at distance 2.
const maxEditDistance = getAutoMaxEditDistance(normalizedToken.length);
const editDistance = calculateOptimizedEditDistance(chunk, normalizedToken, maxEditDistance);
diff --git a/packages/trilium-core/src/services/search/services/search.ts b/packages/trilium-core/src/services/search/services/search.ts
index 86db7746a3..240222586b 100644
--- a/packages/trilium-core/src/services/search/services/search.ts
+++ b/packages/trilium-core/src/services/search/services/search.ts
@@ -322,9 +322,14 @@ function findResultsWithExpression(expression: Expression, searchContext: Search
}
/**
- * How many results the second ranking pass keeps. Generous against the 25 a dropdown shows, so the
- * path contribution -- weighted at {@link SCORE_WEIGHTS.PATH_FACTOR} and worth a few points against
- * title weights in the hundreds -- cannot promote anything from outside it into what is returned.
+ * How many results the second ranking pass keeps: a rescoring window, in the sense Elasticsearch's
+ * `rescore` uses. Results outside it are never path-scored and so cannot move, which makes the
+ * window an approximation of a full ranking rather than an equivalent of one.
+ *
+ * It is set generously against the 25 a dropdown shows, and the distance it has to absorb is much
+ * larger than what the path can contribute: on a 22k-note database the base score at rank 25 sits
+ * 8 to 1500 points above the score at rank 200, while the largest path contribution observed was
+ * 24. The returned 25 came out identical to a full one-pass ranking for every query measured.
*/
const RANK_SHORTLIST = 200;
diff --git a/packages/trilium-core/src/services/search/services/types.ts b/packages/trilium-core/src/services/search/services/types.ts
index 4c05719f06..4f4ad36770 100644
--- a/packages/trilium-core/src/services/search/services/types.ts
+++ b/packages/trilium-core/src/services/search/services/types.ts
@@ -21,7 +21,7 @@ export interface SearchParams {
limit?: number | null;
debug?: boolean;
fuzzyAttributeSearch?: boolean;
- /** When true, skip the two-phase fuzzy fallback and use the single-token fast path. */
+ /** When true, a single-token flat-text search resolves each match's best note path directly. */
autocomplete?: boolean;
/**
* Narrows the `searchEnableFuzzyMatching` option for one surface: false turns fuzzy matching