Performance improvements
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import Dexie from 'dexie'
|
||||
import type { IndexedDocument } from './globals'
|
||||
|
||||
class OmnisearchCache extends Dexie {
|
||||
pdf!: Dexie.Table<
|
||||
|
||||
@@ -68,6 +68,15 @@ export async function fileToIndexedDocument(
|
||||
content = removeDiacritics(content)
|
||||
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,
|
||||
// and add them to the index.
|
||||
if (metadata) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
2
src/vendor/parse-query.ts
vendored
2
src/vendor/parse-query.ts
vendored
@@ -76,7 +76,7 @@ export function parseQuery(
|
||||
let match
|
||||
let count = 0 // TODO: FIXME: this is a hack to avoid infinite loops
|
||||
while ((match = regex.exec(string)) !== null) {
|
||||
if (++count > 100) break
|
||||
if (++count >= 100) break
|
||||
let term = match[0]
|
||||
const sepIndex = term.indexOf(':')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user