Skip to content

Commit

Permalink
WIP indexing non-existing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
scambier committed May 26, 2024
1 parent 85b7810 commit 0b70cbe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
15 changes: 9 additions & 6 deletions src/cache-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
)
Expand Down
15 changes: 8 additions & 7 deletions src/notes-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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()
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -94,7 +96,6 @@ export class NotesIndexer {
doesNotExist: true,
parent,
}
// searchEngine.addDocuments([note])
}

public isFilePlaintext(path: string): boolean {
Expand Down

0 comments on commit 0b70cbe

Please sign in to comment.