Skip to content

Commit

Permalink
Fixed bug in LuceneStore not indexing empty arrays properly
Browse files Browse the repository at this point in the history
Updated SplitStore to not re-index collections with no indexes
  • Loading branch information
darkfrog26 committed Dec 21, 2024
1 parent df797ba commit e4eb289
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ val developerURL: String = "https://matthicks.com"

name := projectName
ThisBuild / organization := org
ThisBuild / version := "1.2.2"
ThisBuild / scalaVersion := scala213
ThisBuild / version := "1.2.3-SNAPSHOT"
ThisBuild / scalaVersion := scala3
ThisBuild / crossScalaVersions := allScalaVersions
ThisBuild / scalacOptions ++= Seq("-unchecked", "-deprecation")

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/lightdb/store/split/SplitStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ case class SplitStore[Doc <: Document[Doc], Model <: DocumentModel[Doc]](overrid
override def verify(): Boolean = transaction { implicit transaction =>
val storageCount = storage.count
val searchCount = searching.count
if (storageCount != searchCount) {
if (storageCount != searchCount && model.fields.count(_.indexed) > 1) {
scribe.warn(s"$name out of sync! Storage Count: $storageCount, Search Count: $searchCount. Re-Indexing...")
reIndexInternal()
scribe.info(s"$name re-indexed successfully!")
Expand Down
6 changes: 6 additions & 0 deletions core/src/test/scala/spec/AbstractBasicSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ abstract class AbstractBasicSpec extends AnyWordSpec with Matchers { spec =>
people.map(_.name) should be(List("Oscar"))
}
}
"materialize empty nicknames" in {
db.people.transaction { implicit transaction =>
val people = db.people.query.filter(_.name === "Ian").search.materialized(p => List(p.nicknames)).list
people.map(m => m(_.nicknames)) should be(List(Set.empty))
}
}
"query with single-value, multiple nicknames" in {
db.people.transaction { implicit transaction =>
val people = db.people.query
Expand Down
8 changes: 7 additions & 1 deletion lucene/src/main/scala/lightdb/lucene/LuceneStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ class LuceneStore[Doc <: Document[Doc], Model <: DocumentModel[Doc]](name: Strin
case DefType.Opt(d) => addJson(json, d)
case DefType.Json | DefType.Obj(_, _) => add(new StringField(field.name, JsonFormatter.Compact(json), fs))
case _ if json == Null => // Ignore null values
case DefType.Arr(d) => json.asVector.foreach(json => addJson(json, d))
case DefType.Arr(d) =>
val v = json.asVector
if (v.isEmpty) {
add(new StringField(field.name, "[]", fs))
} else {
v.foreach(json => addJson(json, d))
}
case DefType.Bool => add(new IntField(field.name, if (json.asBoolean) 1 else 0, fs))
case DefType.Int => add(new LongField(field.name, json.asLong, fs))
case DefType.Dec => add(new DoubleField(field.name, json.asDouble, fs))
Expand Down

0 comments on commit e4eb289

Please sign in to comment.