Skip to content

Commit

Permalink
Merge branch '1.0' into extract-lucene
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Apr 9, 2024
2 parents 31d11c7 + 2349c24 commit 051a3c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/src/test/scala/spec/SimpleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import lightdb.query._
import lightdb.upgrade.DatabaseUpgrade
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec
import scribe.{Level, Logger}

import java.nio.file.Paths

Expand All @@ -20,6 +21,7 @@ class SimpleSpec extends AsyncWordSpec with AsyncIOSpec with Matchers {

"Simple database" should {
"initialize the database" in {
Logger("com.oath.halodb").withMinimumLevel(Level.Warn).replace()
DB.init(truncate = true)
}
"store John Doe" in {
Expand Down
11 changes: 10 additions & 1 deletion lucene/src/main/scala/lightdb/lucene/index/StringField.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import lightdb.lucene.LuceneIndexedField
import lightdb.query.Filter
import lightdb.{Collection, Document}
import org.apache.lucene.index.Term
import org.apache.lucene.search.{SortField, TermQuery}
import org.apache.lucene.search.{BooleanClause, BooleanQuery, SortField, TermQuery}
import org.apache.lucene.{document => ld}

case class StringField[D <: Document[D]](fieldName: String,
Expand All @@ -16,6 +16,15 @@ case class StringField[D <: Document[D]](fieldName: String,

def is(value: String): Filter[D] = Filter(new TermQuery(new Term(fieldName, value)))

def includedIn(values: Seq[String]): Filter[D] = {
val b = new BooleanQuery.Builder
b.setMinimumNumberShouldMatch(1)
values.foreach { value =>
b.add(is(value).asQuery, BooleanClause.Occur.SHOULD)
}
Filter(b.build())
}

override protected[lightdb] def createFields(doc: D): List[ld.Field] = List(
new ld.StringField(fieldName, get(doc), if (store) ld.Field.Store.YES else ld.Field.Store.NO)
)
Expand Down

0 comments on commit 051a3c7

Please sign in to comment.