diff --git a/src/cache-manager.ts b/src/cache-manager.ts index 105ed6e..6b8ebaf 100644 --- a/src/cache-manager.ts +++ b/src/cache-manager.ts @@ -199,12 +199,15 @@ export class CacheManager { // Look for links that lead to non-existing files, // and add them to the index. if (metadata) { - // const nonExisting = getNonExistingNotes(this.plugin.app, file, metadata) - // for (const name of nonExisting.filter( - // o => !this.getLiveDocument(o) - // )) { - // NotesIndex.addNonExistingToIndex(name, file.path) - // } + const nonExisting = getNonExistingNotes(this.plugin.app, file, metadata) + for (const name of nonExisting.filter(o => !this.documents.has(o))) { + const doc = + this.plugin.notesIndexer.generateIndexableNonexistingDocument( + name, + file.path + ) + // TODO: index non-existing note + } // EXCALIDRAW // Remove the json code diff --git a/src/main.ts b/src/main.ts index 3f1610d..bb39151 100644 --- a/src/main.ts +++ b/src/main.ts @@ -117,7 +117,7 @@ export default class OmnisearchPlugin extends Plugin { if (this.notesIndexer.isFileIndexable(file.path)) { logDebug('Updating file', file.path) await this.cacheManager.addToLiveCache(file.path) - this.notesIndexer.markNoteForReindex(file) + this.notesIndexer.flagNoteForReindex(file) } }) ) diff --git a/src/notes-indexer.ts b/src/notes-indexer.ts index cffaf6e..611051b 100644 --- a/src/notes-indexer.ts +++ b/src/notes-indexer.ts @@ -18,16 +18,15 @@ export class NotesIndexer { * Updated notes are not reindexed immediately for performance reasons. * They're added to a list, and reindex is done the next time we open Omnisearch. */ - public markNoteForReindex(note: TAbstractFile): void { + public flagNoteForReindex(note: TAbstractFile): void { this.notesToReindex.add(note) } public async refreshIndex(): Promise { const paths = [...this.notesToReindex].map(n => n.path) if (paths.length) { - const searchEngine = this.plugin.searchEngine - searchEngine.removeFromPaths(paths) - await searchEngine.addFromPaths(paths) + this.plugin.searchEngine.removeFromPaths(paths) + await this.plugin.searchEngine.addFromPaths(paths) this.notesToReindex.clear() } } @@ -73,11 +72,14 @@ export class NotesIndexer { * @param name * @param parent The note referencing the */ - public addNonExistingToIndex(name: string, parent: string): void { + public generateIndexableNonexistingDocument( + name: string, + parent: string + ): IndexedDocument { name = removeAnchors(name) const filename = name + (name.endsWith('.md') ? '' : '.md') - const note: IndexedDocument = { + return { path: filename, basename: name, mtime: 0, @@ -94,7 +96,6 @@ export class NotesIndexer { doesNotExist: true, parent, } - // searchEngine.addDocuments([note]) } public isFilePlaintext(path: string): boolean {