diff --git a/src/database.ts b/src/database.ts index 38d3098..29e1963 100644 --- a/src/database.ts +++ b/src/database.ts @@ -1,5 +1,4 @@ import Dexie from 'dexie' -import type { IndexedDocument } from './globals' class OmnisearchCache extends Dexie { pdf!: Dexie.Table< diff --git a/src/file-loader.ts b/src/file-loader.ts index 7be6289..3b46ace 100644 --- a/src/file-loader.ts +++ b/src/file-loader.ts @@ -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) { diff --git a/src/search/search.ts b/src/search/search.ts index 982bc84..3731c6d 100644 --- a/src/search/search.ts +++ b/src/search/search.ts @@ -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, diff --git a/src/vendor/parse-query.ts b/src/vendor/parse-query.ts index 9d56d64..a7180a9 100644 --- a/src/vendor/parse-query.ts +++ b/src/vendor/parse-query.ts @@ -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(':')