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

@@ -1,5 +1,4 @@
import Dexie from 'dexie' import Dexie from 'dexie'
import type { IndexedDocument } from './globals'
class OmnisearchCache extends Dexie { class OmnisearchCache extends Dexie {
pdf!: Dexie.Table< pdf!: Dexie.Table<

View File

@@ -68,6 +68,15 @@ export async function fileToIndexedDocument(
content = removeDiacritics(content) content = removeDiacritics(content)
const metadata = app.metadataCache.getFileCache(file) const metadata = app.metadataCache.getFileCache(file)
// EXCALIDRAW
// Remove the json code
if (metadata?.frontmatter?.['excalidraw-plugin']) {
const comments = metadata.sections?.filter(s => s.type === 'comment') ?? []
for (const { start, end } of comments.map(c => c.position)) {
content = content.substring(0, start.offset-1) + content.substring(end.offset)
}
}
// Look for links that lead to non-existing files, // Look for links that lead to non-existing files,
// and add them to the index. // and add them to the index.
if (metadata) { if (metadata) {

View File

@@ -140,7 +140,7 @@ export function getMatches(
const matches: SearchMatch[] = [] const matches: SearchMatch[] = []
let count = 0 let count = 0
while ((match = reg.exec(text)) !== null) { 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] const m = match[0]
if (m) matches.push({ match: m, offset: match.index }) if (m) matches.push({ match: m, offset: match.index })
} }
@@ -218,19 +218,14 @@ export async function getSuggestions(
// do not necessarily match the query // do not necessarily match the query
...Object.keys(result.match), ...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 // Quoted expressions
...query.segments.filter(s => s.exact).map(s => s.value), ...query.segments.filter(s => s.exact).map(s => s.value),
// Tags, starting with # // Tags, starting with #
...tags, ...tags,
] ].filter(w => w.length > 1)
// console.log(foundWords)
const matches = getMatches(note.content, stringsToRegex(foundWords), query) const matches = getMatches(note.content, stringsToRegex(foundWords), query)
const resultNote: ResultNote = { const resultNote: ResultNote = {
score: result.score, score: result.score,

View File

@@ -76,7 +76,7 @@ export function parseQuery(
let match let match
let count = 0 // TODO: FIXME: this is a hack to avoid infinite loops let count = 0 // TODO: FIXME: this is a hack to avoid infinite loops
while ((match = regex.exec(string)) !== null) { while ((match = regex.exec(string)) !== null) {
if (++count > 100) break if (++count >= 100) break
let term = match[0] let term = match[0]
const sepIndex = term.indexOf(':') const sepIndex = term.indexOf(':')