From e68487d09538147d3544fe1c5d563ff5151226b4 Mon Sep 17 00:00:00 2001 From: Matt Hicks Date: Fri, 5 Apr 2024 21:09:36 -0500 Subject: [PATCH] This may be entirely pointless --- .../src/main/scala/benchmark/LightDBImplementation.scala | 5 ++++- core/shared/src/main/scala/lightdb/index/SearchResults.scala | 4 ++-- .../src/main/scala/lightdb/index/lucene/LuceneIndexer.scala | 1 + .../src/main/scala/lightdb/index/lucene/SearchManager.scala | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/benchmark/src/main/scala/benchmark/LightDBImplementation.scala b/benchmark/src/main/scala/benchmark/LightDBImplementation.scala index d4b04148..681728fe 100644 --- a/benchmark/src/main/scala/benchmark/LightDBImplementation.scala +++ b/benchmark/src/main/scala/benchmark/LightDBImplementation.scala @@ -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() diff --git a/core/shared/src/main/scala/lightdb/index/SearchResults.scala b/core/shared/src/main/scala/lightdb/index/SearchResults.scala index 24f65fa0..2a0f300d 100644 --- a/core/shared/src/main/scala/lightdb/index/SearchResults.scala +++ b/core/shared/src/main/scala/lightdb/index/SearchResults.scala @@ -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()) } \ No newline at end of file diff --git a/lucene/src/main/scala/lightdb/index/lucene/LuceneIndexer.scala b/lucene/src/main/scala/lightdb/index/lucene/LuceneIndexer.scala index fd7df366..cf6b790d 100644 --- a/lucene/src/main/scala/lightdb/index/lucene/LuceneIndexer.scala +++ b/lucene/src/main/scala/lightdb/index/lucene/LuceneIndexer.scala @@ -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()) diff --git a/lucene/src/main/scala/lightdb/index/lucene/SearchManager.scala b/lucene/src/main/scala/lightdb/index/lucene/SearchManager.scala index faa87f6d..27a12845 100644 --- a/lucene/src/main/scala/lightdb/index/lucene/SearchManager.scala +++ b/lucene/src/main/scala/lightdb/index/lucene/SearchManager.scala @@ -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 }