Skip to content

Commit

Permalink
This may be entirely pointless
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Apr 6, 2024
1 parent cf34cb2 commit e68487d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ object LightDBImplementation extends BenchmarkImplementation {

override def get(id: String): IO[TitleAkaLDB] = db.titleAka.get(Id[TitleAkaLDB](id)).map(_.getOrElse(throw new RuntimeException(s"$id not found")))

override def findByTitleId(titleId: String): IO[List[TitleAkaLDB]] = db.titleAka.query.filter(TitleAkaLDB.titleId === titleId).documentsStream().compile.toList
override def findByTitleId(titleId: String): IO[List[TitleAkaLDB]] = db.titleAka.query
.scoreDocs(false)
.filter(TitleAkaLDB.titleId === titleId)
.toList

override def flush(): IO[Unit] = for {
_ <- db.titleAka.commit()
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/lightdb/index/SearchResults.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package lightdb.index

import cats.effect.IO
import fs2.Stream
import lightdb.Document
import lightdb.{Document, Id}
import lightdb.query.Query

case class SearchResults[D <: Document[D]](query: Query[D],
total: Int,
stream: Stream[IO, SearchResult[D]]) {
ids: List[Id[D]]) {
def documentsStream(): fs2.Stream[IO, D] = stream.evalMap(_.get())
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ case class LuceneIndexer[D <: Document[D]](collection: Collection[D],
private def commitBlocking(): Unit = {
indexWriter.flush()
indexWriter.commit()
searchManager.dirty()
}

override def commit(): IO[Unit] = IO(commitBlocking())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ case class SearchManager(indexWriter: IndexWriter) {
private lazy val searcherManager = new SearcherManager(indexWriter, new SearcherFactory)

def apply[Return](f: IndexSearcher => IO[Return]): IO[Return] = {
searcherManager.maybeRefresh()
val searcher = searcherManager.acquire()
f(searcher)
.guarantee(IO(searcherManager.release(searcher)))
}

def dirty(): Unit = searcherManager.maybeRefreshBlocking()

def dispose(): IO[Unit] = IO.unit
}

0 comments on commit e68487d

Please sign in to comment.