Index all notes at start

This commit is contained in:
2020-08-19 16:45:55 +02:00
parent ab3766b8b8
commit 12619f6550
10 changed files with 60 additions and 2 deletions
+15
View File
@@ -52,6 +52,21 @@ class NoteSearcher(basePath: Path = Path.of("/tmp", "lucene")) {
}
}
fun indexNotes(userId: Int, notes: List<PersistedNote>) {
logger.debug("Indexing notes for user $userId")
val dir = getDirectory(userId)
val config = IndexWriterConfig(StandardAnalyzer())
val writer = IndexWriter(dir, config)
val docs = notes.map { it.toDocument() }
with(writer) {
addDocuments(docs)
commit()
close()
}
}
fun deleteIndex(userId: Int, uuid: UUID) {
logger.debug("Deleting indexing $uuid for user $userId")
+2 -1
View File
@@ -1,7 +1,8 @@
package be.simplenotes.search
import org.koin.dsl.module
import java.nio.file.Path
val searchModule = module {
single { NoteSearcher() }
single { NoteSearcher(Path.of(".lucene")) }
}