Better error handling

This commit is contained in:
2020-08-21 19:31:24 +02:00
parent b27fd29230
commit 36600bb1f4
6 changed files with 68 additions and 15 deletions
+6 -1
View File
@@ -1,6 +1,7 @@
package be.simplenotes.search
import be.simplenotes.domain.model.PersistedNote
import be.simplenotes.domain.model.PersistedNoteMetadata
import be.simplenotes.domain.usecases.search.NoteSearcher
import be.simplenotes.domain.usecases.search.SearchTerms
import be.simplenotes.search.utils.rmdir
@@ -80,13 +81,17 @@ class NoteSearcherImpl(basePath: Path = Path.of("/tmp", "lucene")) : NoteSearche
indexNote(userId, note)
}
override fun search(userId: Int, terms: SearchTerms) =
override fun search(userId: Int, terms: SearchTerms) = try {
indexSearcher(userId).query {
or { titleField eq terms.title }
or { tagsField eq terms.tag }
or { contentField eq terms.content }
listOf(titleField, tagsField, contentField) anyMatch terms.all
}.map(Document::toNoteMeta)
} catch (e: IndexNotFoundException) {
logger.warn("Index not found for user $userId")
emptyList()
}
override fun dropIndex(userId: Int) = rmdir(File(baseFile, userId.toString()).toPath())