Fix circular dependency
This commit is contained in:
parent
68109f8666
commit
08c804ccb5
@ -14,6 +14,11 @@
|
|||||||
<artifactId>persistance</artifactId>
|
<artifactId>persistance</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>be.simplenotes</groupId>
|
||||||
|
<artifactId>search</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>be.simplenotes</groupId>
|
<groupId>be.simplenotes</groupId>
|
||||||
<artifactId>domain</artifactId>
|
<artifactId>domain</artifactId>
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import be.simplenotes.domain.usecases.NoteService
|
|||||||
import be.simplenotes.domain.usecases.markdown.InvalidMeta
|
import be.simplenotes.domain.usecases.markdown.InvalidMeta
|
||||||
import be.simplenotes.domain.usecases.markdown.MissingMeta
|
import be.simplenotes.domain.usecases.markdown.MissingMeta
|
||||||
import be.simplenotes.domain.usecases.markdown.ValidationError
|
import be.simplenotes.domain.usecases.markdown.ValidationError
|
||||||
import be.simplenotes.search.SearchTerms
|
import be.simplenotes.domain.usecases.search.SearchTerms
|
||||||
import org.http4k.core.Method
|
import org.http4k.core.Method
|
||||||
import org.http4k.core.Request
|
import org.http4k.core.Request
|
||||||
import org.http4k.core.Response
|
import org.http4k.core.Response
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package be.simplenotes.app.utils
|
package be.simplenotes.app.utils
|
||||||
|
|
||||||
import be.simplenotes.search.SearchTerms
|
import be.simplenotes.domain.usecases.search.SearchTerms
|
||||||
|
|
||||||
private val titleRe = """title:['"](?<title>.*?)['"]""".toRegex()
|
private val titleRe = """title:['"](?<title>.*?)['"]""".toRegex()
|
||||||
private val outerTitleRe = """(?<title>title:['"].*?['"])""".toRegex()
|
private val outerTitleRe = """(?<title>title:['"].*?['"])""".toRegex()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package be.simplenotes.app.utils
|
package be.simplenotes.app.utils
|
||||||
|
|
||||||
import be.simplenotes.search.SearchTerms
|
import be.simplenotes.domain.usecases.search.SearchTerms
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.params.ParameterizedTest
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
import org.junit.jupiter.params.provider.MethodSource
|
import org.junit.jupiter.params.provider.MethodSource
|
||||||
|
|||||||
@ -14,11 +14,6 @@
|
|||||||
<artifactId>shared</artifactId>
|
<artifactId>shared</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>be.simplenotes</groupId>
|
|
||||||
<artifactId>search</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>be.simplenotes</groupId>
|
<groupId>be.simplenotes</groupId>
|
||||||
<artifactId>shared</artifactId>
|
<artifactId>shared</artifactId>
|
||||||
|
|||||||
@ -10,8 +10,8 @@ import be.simplenotes.domain.usecases.markdown.MarkdownConverter
|
|||||||
import be.simplenotes.domain.usecases.markdown.MarkdownParsingError
|
import be.simplenotes.domain.usecases.markdown.MarkdownParsingError
|
||||||
import be.simplenotes.domain.usecases.repositories.NoteRepository
|
import be.simplenotes.domain.usecases.repositories.NoteRepository
|
||||||
import be.simplenotes.domain.usecases.repositories.UserRepository
|
import be.simplenotes.domain.usecases.repositories.UserRepository
|
||||||
import be.simplenotes.search.NoteSearcher
|
import be.simplenotes.domain.usecases.search.NoteSearcher
|
||||||
import be.simplenotes.search.SearchTerms
|
import be.simplenotes.domain.usecases.search.SearchTerms
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class NoteService(
|
class NoteService(
|
||||||
|
|||||||
17
domain/src/main/kotlin/usecases/search/SearchUseCase.kt
Normal file
17
domain/src/main/kotlin/usecases/search/SearchUseCase.kt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package be.simplenotes.domain.usecases.search
|
||||||
|
|
||||||
|
import be.simplenotes.domain.model.PersistedNote
|
||||||
|
import be.simplenotes.domain.model.PersistedNoteMetadata
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
data class SearchTerms(val title: String?, val tag: String?, val content: String?)
|
||||||
|
|
||||||
|
interface NoteSearcher {
|
||||||
|
fun indexNote(userId: Int, note: PersistedNote)
|
||||||
|
fun indexNotes(userId: Int, notes: List<PersistedNote>)
|
||||||
|
fun deleteIndex(userId: Int, uuid: UUID)
|
||||||
|
fun updateIndex(userId: Int, note: PersistedNote)
|
||||||
|
fun search(userId: Int, terms: SearchTerms): List<PersistedNoteMetadata>
|
||||||
|
fun dropIndex(userId: Int)
|
||||||
|
fun dropAll()
|
||||||
|
}
|
||||||
@ -2,6 +2,8 @@ package be.simplenotes.search
|
|||||||
|
|
||||||
import be.simplenotes.domain.model.PersistedNote
|
import be.simplenotes.domain.model.PersistedNote
|
||||||
import be.simplenotes.domain.model.PersistedNoteMetadata
|
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
|
import be.simplenotes.search.utils.rmdir
|
||||||
import org.apache.lucene.analysis.standard.StandardAnalyzer
|
import org.apache.lucene.analysis.standard.StandardAnalyzer
|
||||||
import org.apache.lucene.index.*
|
import org.apache.lucene.index.*
|
||||||
@ -10,17 +12,10 @@ import org.apache.lucene.store.Directory
|
|||||||
import org.apache.lucene.store.FSDirectory
|
import org.apache.lucene.store.FSDirectory
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
|
||||||
import java.nio.file.FileVisitResult
|
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.SimpleFileVisitor
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
data class SearchTerms(val title: String?, val tag: String?, val content: String?)
|
class NoteSearcherImpl(basePath: Path = Path.of("/tmp", "lucene")) : NoteSearcher {
|
||||||
|
|
||||||
class NoteSearcher(basePath: Path = Path.of("/tmp", "lucene")) {
|
|
||||||
private val baseFile = basePath.toFile()
|
private val baseFile = basePath.toFile()
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(javaClass)
|
private val logger = LoggerFactory.getLogger(javaClass)
|
||||||
@ -38,7 +33,7 @@ class NoteSearcher(basePath: Path = Path.of("/tmp", "lucene")) {
|
|||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
fun indexNote(userId: Int, note: PersistedNote) {
|
override fun indexNote(userId: Int, note: PersistedNote) {
|
||||||
logger.debug("Indexing note ${note.uuid} for user $userId")
|
logger.debug("Indexing note ${note.uuid} for user $userId")
|
||||||
|
|
||||||
val dir = getDirectory(userId)
|
val dir = getDirectory(userId)
|
||||||
@ -53,7 +48,7 @@ class NoteSearcher(basePath: Path = Path.of("/tmp", "lucene")) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun indexNotes(userId: Int, notes: List<PersistedNote>) {
|
override fun indexNotes(userId: Int, notes: List<PersistedNote>) {
|
||||||
logger.debug("Indexing notes for user $userId")
|
logger.debug("Indexing notes for user $userId")
|
||||||
|
|
||||||
val dir = getDirectory(userId)
|
val dir = getDirectory(userId)
|
||||||
@ -68,7 +63,7 @@ class NoteSearcher(basePath: Path = Path.of("/tmp", "lucene")) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteIndex(userId: Int, uuid: UUID) {
|
override fun deleteIndex(userId: Int, uuid: UUID) {
|
||||||
logger.debug("Deleting index $uuid for user $userId")
|
logger.debug("Deleting index $uuid for user $userId")
|
||||||
|
|
||||||
val dir = getDirectory(userId)
|
val dir = getDirectory(userId)
|
||||||
@ -82,13 +77,13 @@ class NoteSearcher(basePath: Path = Path.of("/tmp", "lucene")) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateIndex(userId: Int, note: PersistedNote) {
|
override fun updateIndex(userId: Int, note: PersistedNote) {
|
||||||
logger.debug("Updating note ${note.uuid} for user $userId")
|
logger.debug("Updating note ${note.uuid} for user $userId")
|
||||||
deleteIndex(userId, note.uuid)
|
deleteIndex(userId, note.uuid)
|
||||||
indexNote(userId, note)
|
indexNote(userId, note)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun search(userId: Int, terms: SearchTerms): List<PersistedNoteMetadata> {
|
override fun search(userId: Int, terms: SearchTerms): List<PersistedNoteMetadata> {
|
||||||
val searcher = getIndexSearcher(userId)
|
val searcher = getIndexSearcher(userId)
|
||||||
|
|
||||||
val builder = BooleanQuery.Builder()
|
val builder = BooleanQuery.Builder()
|
||||||
@ -115,8 +110,8 @@ class NoteSearcher(basePath: Path = Path.of("/tmp", "lucene")) {
|
|||||||
return topDocs.toResults(searcher)
|
return topDocs.toResults(searcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dropIndex(userId: Int) = rmdir(File(baseFile, userId.toString()).toPath())
|
override fun dropIndex(userId: Int) = rmdir(File(baseFile, userId.toString()).toPath())
|
||||||
|
|
||||||
fun dropAll() = rmdir(baseFile.toPath())
|
override fun dropAll() = rmdir(baseFile.toPath())
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,8 +1,9 @@
|
|||||||
package be.simplenotes.search
|
package be.simplenotes.search
|
||||||
|
|
||||||
|
import be.simplenotes.domain.usecases.search.NoteSearcher
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
val searchModule = module {
|
val searchModule = module {
|
||||||
single { NoteSearcher(Path.of(".lucene")) }
|
single<NoteSearcher> { NoteSearcherImpl(Path.of(".lucene")) }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package be.simplenotes.search
|
|||||||
import be.simplenotes.domain.model.NoteMetadata
|
import be.simplenotes.domain.model.NoteMetadata
|
||||||
import be.simplenotes.domain.model.PersistedNote
|
import be.simplenotes.domain.model.PersistedNote
|
||||||
import be.simplenotes.domain.model.PersistedNoteMetadata
|
import be.simplenotes.domain.model.PersistedNoteMetadata
|
||||||
|
import be.simplenotes.domain.usecases.search.SearchTerms
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import org.junit.jupiter.api.AfterAll
|
import org.junit.jupiter.api.AfterAll
|
||||||
@ -13,10 +14,10 @@ import java.time.LocalDateTime
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ResourceLock("lucene")
|
@ResourceLock("lucene")
|
||||||
internal class NoteSearcherTest {
|
internal class NoteSearcherImplTest {
|
||||||
|
|
||||||
// region setup
|
// region setup
|
||||||
private val searcher = NoteSearcher()
|
private val searcher = NoteSearcherImpl()
|
||||||
|
|
||||||
private fun index(
|
private fun index(
|
||||||
title: String,
|
title: String,
|
||||||
Loading…
x
Reference in New Issue
Block a user