mirror of
https://github.com/zadam/trilium.git
synced 2025-11-14 18:39:01 +01:00
fix(quick_search): resolve word issues to not trigger substring matches (#7708)
Some checks are pending
Checks / main (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Deploy Documentation / Build and Deploy Documentation (push) Waiting to run
Dev / Test development (push) Waiting to run
Dev / Build Docker image (push) Blocked by required conditions
Dev / Check Docker build (Dockerfile) (push) Blocked by required conditions
Dev / Check Docker build (Dockerfile.alpine) (push) Blocked by required conditions
/ Check Docker build (Dockerfile) (push) Waiting to run
/ Check Docker build (Dockerfile.alpine) (push) Waiting to run
/ Build Docker images (Dockerfile, ubuntu-24.04-arm, linux/arm64) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.alpine, ubuntu-latest, linux/amd64) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.legacy, ubuntu-24.04-arm, linux/arm/v7) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.legacy, ubuntu-24.04-arm, linux/arm/v8) (push) Blocked by required conditions
/ Merge manifest lists (push) Blocked by required conditions
playwright / E2E tests on linux-arm64 (push) Waiting to run
playwright / E2E tests on linux-x64 (push) Waiting to run
Deploy website / Build & deploy website (push) Waiting to run
Some checks are pending
Checks / main (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Deploy Documentation / Build and Deploy Documentation (push) Waiting to run
Dev / Test development (push) Waiting to run
Dev / Build Docker image (push) Blocked by required conditions
Dev / Check Docker build (Dockerfile) (push) Blocked by required conditions
Dev / Check Docker build (Dockerfile.alpine) (push) Blocked by required conditions
/ Check Docker build (Dockerfile) (push) Waiting to run
/ Check Docker build (Dockerfile.alpine) (push) Waiting to run
/ Build Docker images (Dockerfile, ubuntu-24.04-arm, linux/arm64) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.alpine, ubuntu-latest, linux/amd64) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.legacy, ubuntu-24.04-arm, linux/arm/v7) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.legacy, ubuntu-24.04-arm, linux/arm/v8) (push) Blocked by required conditions
/ Merge manifest lists (push) Blocked by required conditions
playwright / E2E tests on linux-arm64 (push) Waiting to run
playwright / E2E tests on linux-x64 (push) Waiting to run
Deploy website / Build & deploy website (push) Waiting to run
This commit is contained in:
commit
4f580a37a3
@ -113,7 +113,16 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
const normalizedFlatText = normalizeSearchText(flatText);
|
const normalizedFlatText = normalizeSearchText(flatText);
|
||||||
|
|
||||||
// Check if =phrase appears in flatText (indicates attribute value match)
|
// Check if =phrase appears in flatText (indicates attribute value match)
|
||||||
matches = normalizedFlatText.includes(`=${normalizedPhrase}`);
|
// For single words, use word-boundary matching to avoid substring matches
|
||||||
|
if (!normalizedPhrase.includes(' ')) {
|
||||||
|
// Single word: look for =word with word boundaries
|
||||||
|
// Split by = to get attribute values, then check each value for exact word match
|
||||||
|
const parts = normalizedFlatText.split('=');
|
||||||
|
matches = parts.slice(1).some(part => this.exactWordMatch(normalizedPhrase, part));
|
||||||
|
} else {
|
||||||
|
// Multi-word phrase: check for substring match
|
||||||
|
matches = normalizedFlatText.includes(`=${normalizedPhrase}`);
|
||||||
|
}
|
||||||
|
|
||||||
if ((this.operator === "=" && matches) || (this.operator === "!=" && !matches)) {
|
if ((this.operator === "=" && matches) || (this.operator === "!=" && !matches)) {
|
||||||
resultNoteSet.add(noteFromBecca);
|
resultNoteSet.add(noteFromBecca);
|
||||||
@ -124,6 +133,17 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
return resultNoteSet;
|
return resultNoteSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to check if a single word appears as an exact match in text
|
||||||
|
* @param wordToFind - The word to search for (should be normalized)
|
||||||
|
* @param text - The text to search in (should be normalized)
|
||||||
|
* @returns true if the word is found as an exact match (not substring)
|
||||||
|
*/
|
||||||
|
private exactWordMatch(wordToFind: string, text: string): boolean {
|
||||||
|
const words = text.split(/\s+/);
|
||||||
|
return words.some(word => word === wordToFind);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if content contains the exact word (with word boundaries) or exact phrase
|
* Checks if content contains the exact word (with word boundaries) or exact phrase
|
||||||
* This is case-insensitive since content and token are already normalized
|
* This is case-insensitive since content and token are already normalized
|
||||||
@ -139,9 +159,8 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
return normalizedContent.includes(normalizedToken);
|
return normalizedContent.includes(normalizedToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For single words, split content into words and check for exact match
|
// For single words, use exact word matching to avoid substring matches
|
||||||
const words = normalizedContent.split(/\s+/);
|
return this.exactWordMatch(normalizedToken, normalizedContent);
|
||||||
return words.some(word => word === normalizedToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,7 +174,14 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
// Join tokens with single space to form the phrase
|
// Join tokens with single space to form the phrase
|
||||||
const phrase = normalizedTokens.join(" ");
|
const phrase = normalizedTokens.join(" ");
|
||||||
|
|
||||||
// Check if the phrase appears as a substring (consecutive words)
|
// For single-word phrases, use word-boundary matching to avoid substring matches
|
||||||
|
// e.g., "asd" should not match "asdfasdf"
|
||||||
|
if (!phrase.includes(' ')) {
|
||||||
|
// Single word: use exact word matching to avoid substring matches
|
||||||
|
return this.exactWordMatch(phrase, normalizedContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For multi-word phrases, check if the phrase appears as consecutive words
|
||||||
if (normalizedContent.includes(phrase)) {
|
if (normalizedContent.includes(phrase)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user