Index all notes at start
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
@@ -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")) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user