If possible, show an excerpt that contains the whole query
This commit is contained in:
@@ -98,7 +98,7 @@ async function search(
|
|||||||
app.metadataCache.isUserIgnored &&
|
app.metadataCache.isUserIgnored &&
|
||||||
app.metadataCache.isUserIgnored(result.id)
|
app.metadataCache.isUserIgnored(result.id)
|
||||||
) {
|
) {
|
||||||
result.score /= 3 // TODO: make this value configurable or toggleable?
|
result.score /= 10 // TODO: make this value configurable or toggleable?
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -130,19 +130,30 @@ async function search(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a text against a regex, and returns the { string, offset } matches
|
* Parses a text against a regex, and returns the { string, offset } matches
|
||||||
* @param text
|
|
||||||
* @param reg
|
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
export function getMatches(text: string, reg: RegExp): SearchMatch[] {
|
export function getMatches(
|
||||||
|
text: string,
|
||||||
|
reg: RegExp,
|
||||||
|
query: Query
|
||||||
|
): SearchMatch[] {
|
||||||
let match: RegExpExecArray | null = null
|
let match: RegExpExecArray | null = null
|
||||||
const matches: SearchMatch[] = []
|
const matches: SearchMatch[] = []
|
||||||
let count = 0 // TODO: FIXME: this is a hack to avoid infinite loops
|
let count = 0
|
||||||
while ((match = reg.exec(text)) !== null) {
|
while ((match = reg.exec(text)) !== null) {
|
||||||
if (++count > 100) break
|
if (++count > 100) break // Avoid infinite loops, stop looking after 100 matches
|
||||||
const m = match[0]
|
const m = match[0]
|
||||||
if (m) matches.push({ match: m, offset: match.index })
|
if (m) matches.push({ match: m, offset: match.index })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the query can be found "as is" in the text, put this match first
|
||||||
|
const best = text.toLowerCase().indexOf(query.segmentsToStr())
|
||||||
|
if (best > -1) {
|
||||||
|
matches.unshift({
|
||||||
|
offset: best,
|
||||||
|
match: query.segmentsToStr(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return matches
|
return matches
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +204,7 @@ export async function getSuggestions(
|
|||||||
return results.map(result => {
|
return results.map(result => {
|
||||||
const note = cacheManager.getDocument(result.id)
|
const note = cacheManager.getDocument(result.id)
|
||||||
if (!note) {
|
if (!note) {
|
||||||
throw new Error(`Note "${result.id}" not indexed`)
|
throw new Error(`Omnisearch - Note "${result.id}" not indexed`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove '#' from tags, for highlighting
|
// Remove '#' from tags, for highlighting
|
||||||
@@ -220,7 +231,7 @@ export async function getSuggestions(
|
|||||||
...tags,
|
...tags,
|
||||||
]
|
]
|
||||||
|
|
||||||
const matches = getMatches(note.content, stringsToRegex(foundWords))
|
const matches = getMatches(note.content, stringsToRegex(foundWords), query)
|
||||||
const resultNote: ResultNote = {
|
const resultNote: ResultNote = {
|
||||||
score: result.score,
|
score: result.score,
|
||||||
foundWords,
|
foundWords,
|
||||||
|
|||||||
2
src/vendor/parse-query.ts
vendored
2
src/vendor/parse-query.ts
vendored
@@ -49,7 +49,7 @@ export function parseQuery(
|
|||||||
if (!options) {
|
if (!options) {
|
||||||
options = { offsets: true, tokenize: true }
|
options = { offsets: true, tokenize: true }
|
||||||
} else {
|
} else {
|
||||||
// If options offsets was't passed, set it to true
|
// If options.offsets wasn't passed, set it to true
|
||||||
options.offsets =
|
options.offsets =
|
||||||
typeof options.offsets === 'undefined' ? true : options.offsets
|
typeof options.offsets === 'undefined' ? true : options.offsets
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user