Better error handling
This commit is contained in:
@@ -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())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user