#25 - matching exact expressions in quotes
This works as a post-search filter, so individual words still need to be valid tokens
This commit is contained in:
@@ -76,8 +76,9 @@ async function search(query: string): Promise<SearchResult[]> {
|
|||||||
headings3: 1.1,
|
headings3: 1.1,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const quoted = splitQuotes(query.toLowerCase())
|
|
||||||
|
|
||||||
|
// If the search query contains quotes, filter out results that don't have the exact match
|
||||||
|
const quoted = splitQuotes(query.toLowerCase())
|
||||||
if (quoted.length) {
|
if (quoted.length) {
|
||||||
results = results.filter(r => {
|
results = results.filter(r => {
|
||||||
const content = stripMarkdownCharacters(
|
const content = stripMarkdownCharacters(
|
||||||
@@ -117,6 +118,7 @@ export async function getSuggestions(
|
|||||||
query: string,
|
query: string,
|
||||||
options?: Partial<{ singleFilePath: string | null }>,
|
options?: Partial<{ singleFilePath: string | null }>,
|
||||||
): Promise<ResultNote[]> {
|
): Promise<ResultNote[]> {
|
||||||
|
query = query.toLowerCase()
|
||||||
// Get the raw results
|
// Get the raw results
|
||||||
let results = await search(query)
|
let results = await search(query)
|
||||||
if (!results.length) return []
|
if (!results.length) return []
|
||||||
@@ -138,7 +140,17 @@ export async function getSuggestions(
|
|||||||
if (!note) {
|
if (!note) {
|
||||||
throw new Error(`Note "${result.id}" not indexed`)
|
throw new Error(`Note "${result.id}" not indexed`)
|
||||||
}
|
}
|
||||||
const words = Object.keys(result.match)
|
|
||||||
|
// Clean search matches that match quoted expresins,
|
||||||
|
// and inject those expressions instead
|
||||||
|
const quoted = splitQuotes(query)
|
||||||
|
let words = Object.keys(result.match)
|
||||||
|
for (const quote of quoted) {
|
||||||
|
for (const q of quote.toLowerCase()) {
|
||||||
|
words = words.filter(w => !w.toLowerCase().startsWith(q))
|
||||||
|
}
|
||||||
|
words.push(quote)
|
||||||
|
}
|
||||||
const matches = getMatches(note.content, stringsToRegex(words))
|
const matches = getMatches(note.content, stringsToRegex(words))
|
||||||
const resultNote: ResultNote = {
|
const resultNote: ResultNote = {
|
||||||
score: result.score,
|
score: result.score,
|
||||||
|
|||||||
Reference in New Issue
Block a user