fix: Prioritize exact phrase matches and fix case-sensitive search

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-05 13:09:36 -07:00
parent 3c84980903
commit 2b00a7af2d
2 changed files with 21 additions and 3 deletions

View File

@@ -481,6 +481,15 @@ export class SearchEngine {
query query
) )
let bestMatch: SearchMatch | undefined
if (
matches.length > 0 &&
query.getBestStringForExcerpt() &&
matches[0].match.toLowerCase() === query.getBestStringForExcerpt()
) {
bestMatch = matches.shift()
}
const lowerCaseBasename = note.basename.toLowerCase() const lowerCaseBasename = note.basename.toLowerCase()
const titleMatchWord = foundWords.find(word => const titleMatchWord = foundWords.find(word =>
lowerCaseBasename.includes(word.toLowerCase()) lowerCaseBasename.includes(word.toLowerCase())
@@ -514,6 +523,10 @@ export class SearchEngine {
} }
} }
if (bestMatch) {
matches.unshift(bestMatch)
}
logVerbose(`Matches for note "${note.path}"`, matches) logVerbose(`Matches for note "${note.path}"`, matches)
const resultNote: ResultNote = { const resultNote: ResultNote = {
score: result.score, score: result.score,

View File

@@ -95,11 +95,16 @@ export class TextProcessor {
query && query &&
(query.query.text.length > 1 || query.getExactTerms().length > 0) (query.query.text.length > 1 || query.getExactTerms().length > 0)
) { ) {
const best = text.indexOf(query.getBestStringForExcerpt()) const bestMatchStr = query.getBestStringForExcerpt()
if (best > -1 && matches.find(m => m.offset === best)) { const best = text.toLowerCase().indexOf(bestMatchStr)
if (best > -1) {
// We found the full query. We make it the first result, and remove any other match that it contains.
matches = matches.filter(
m => m.offset < best || m.offset >= best + bestMatchStr.length
)
matches.unshift({ matches.unshift({
offset: best, offset: best,
match: query.getBestStringForExcerpt(), match: originalText.substring(best, best + bestMatchStr.length),
}) })
} }
} }