Performance improvements

This commit is contained in:
Simon Cambier
2022-10-26 07:40:44 +02:00
parent 611ee8d7f4
commit 33e7f8fe25
4 changed files with 13 additions and 10 deletions

View File

@@ -140,7 +140,7 @@ export function getMatches(
const matches: SearchMatch[] = []
let count = 0
while ((match = reg.exec(text)) !== null) {
if (++count > 100) break // Avoid infinite loops, stop looking after 100 matches
if (++count >= 100) break // Avoid infinite loops, stop looking after 100 matches
const m = match[0]
if (m) matches.push({ match: m, offset: match.index })
}
@@ -218,19 +218,14 @@ export async function getSuggestions(
// do not necessarily match the query
...Object.keys(result.match),
// // Matching terms from the query,
// // but only if they stem from the result's matches
// ...Object.keys(result.match).filter(w =>
// query.segments.some(s => w.startsWith(s.value)),
// ),
// Quoted expressions
...query.segments.filter(s => s.exact).map(s => s.value),
// Tags, starting with #
...tags,
]
].filter(w => w.length > 1)
// console.log(foundWords)
const matches = getMatches(note.content, stringsToRegex(foundWords), query)
const resultNote: ResultNote = {
score: result.score,