mirror of
https://github.com/zadam/trilium.git
synced 2025-11-13 09:59:02 +01:00
fix(quick_search): resolve word issues to not trigger substring matches
This commit is contained in:
parent
54d3936c7b
commit
dee8c115ab
@ -113,7 +113,19 @@ 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 => {
|
||||||
|
const words = part.split(/\s+/);
|
||||||
|
return words.some(word => word === normalizedPhrase);
|
||||||
|
});
|
||||||
|
} 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);
|
||||||
@ -155,7 +167,15 @@ 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: split into words and check for exact match
|
||||||
|
const words = normalizedContent.split(/\s+/);
|
||||||
|
return words.some(word => word === phrase);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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