Skip to content

Commit 28ff475

Browse files
committed
feat: add isNull / isNotNull filter
1 parent 3aa5bee commit 28ff475

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

src/it/java/io/weaviate/integration/SearchITest.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import io.weaviate.client6.v1.api.collections.generate.GenerativeObject;
3131
import io.weaviate.client6.v1.api.collections.generate.TaskOutput;
3232
import io.weaviate.client6.v1.api.collections.generative.DummyGenerative;
33+
import io.weaviate.client6.v1.api.collections.query.Filter;
3334
import io.weaviate.client6.v1.api.collections.query.GroupBy;
3435
import io.weaviate.client6.v1.api.collections.query.Metadata;
3536
import io.weaviate.client6.v1.api.collections.query.QueryMetadata;
3637
import io.weaviate.client6.v1.api.collections.query.QueryResponseGroup;
3738
import io.weaviate.client6.v1.api.collections.query.SortBy;
3839
import io.weaviate.client6.v1.api.collections.query.Target;
39-
import io.weaviate.client6.v1.api.collections.query.Filter;
4040
import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw;
4141
import io.weaviate.client6.v1.api.collections.vectorindex.MultiVector;
4242
import io.weaviate.containers.Container;
@@ -608,9 +608,9 @@ public void testGenerative_bm25() throws IOException {
608608
.hasSize(2)
609609
.allSatisfy(obj -> {
610610
Assertions.assertThat(obj).as("uuid shorthand")
611-
.returns(obj.uuid(), GenerativeObject::uuid);
611+
.returns(obj.uuid(), GenerativeObject::uuid);
612612
Assertions.assertThat(obj).as("vectors shorthand")
613-
.returns(obj.vectors(), GenerativeObject::vectors);
613+
.returns(obj.vectors(), GenerativeObject::vectors);
614614
})
615615
.extracting(GenerativeObject::generative)
616616
.allSatisfy(generated -> {
@@ -673,4 +673,31 @@ public void testGenerative_bm25_groupBy() throws IOException {
673673
.extracting(TaskOutput::text, InstanceOfAssertFactories.STRING)
674674
.isNotBlank();
675675
}
676+
677+
@Test
678+
public void test_filterIsNull() throws IOException {
679+
// Arrange
680+
var nsNulls = ns("Nulls");
681+
682+
var nulls = client.collections.create(nsNulls,
683+
c -> c
684+
.invertedIndex(idx -> idx.indexNulls(true))
685+
.properties(Property.text("never")));
686+
687+
var inserted = nulls.data.insertMany(Map.of(), Map.of("never", "notNull"));
688+
Assertions.assertThat(inserted.errors()).isEmpty();
689+
690+
// Act
691+
var isNull = nulls.query.fetchObjects(q -> q.filters(Filter.property("never").isNull()));
692+
var isNotNull = nulls.query.fetchObjects(q -> q.filters(Filter.property("never").isNotNull()));
693+
694+
// Assert
695+
var isNull_1 = Assertions.assertThat(isNull.objects())
696+
.as("objects WHERE never IS NULL")
697+
.hasSize(1).first().actual();
698+
var isNotNull_1 = Assertions.assertThat(isNotNull.objects())
699+
.as("objects WHERE never IS NOT NULL")
700+
.hasSize(1).first().actual();
701+
Assertions.assertThat(isNull_1).isNotEqualTo(isNotNull_1);
702+
}
676703
}

src/main/java/io/weaviate/client6/v1/api/collections/query/Filter.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ private enum Operator {
2222
LESS_THAN_EQUAL("LessThenEqual", WeaviateProtoBase.Filters.Operator.OPERATOR_LESS_THAN_EQUAL),
2323
GREATER_THAN("GreaterThen", WeaviateProtoBase.Filters.Operator.OPERATOR_GREATER_THAN),
2424
GREATER_THAN_EQUAL("GreaterThenEqual", WeaviateProtoBase.Filters.Operator.OPERATOR_GREATER_THAN_EQUAL),
25+
IS_NULL("IsNull", WeaviateProtoBase.Filters.Operator.OPERATOR_IS_NULL),
2526
LIKE("Like", WeaviateProtoBase.Filters.Operator.OPERATOR_LIKE),
2627
CONTAINS_ANY("ContainsAny", WeaviateProtoBase.Filters.Operator.OPERATOR_CONTAINS_ANY),
2728
CONTAINS_ALL("ContainsAll", WeaviateProtoBase.Filters.Operator.OPERATOR_CONTAINS_ALL),
@@ -422,6 +423,20 @@ public Filter gte(Object value) {
422423
return new Filter(Operator.GREATER_THAN_EQUAL, left, fromObject(value));
423424
}
424425

426+
// IsNull
427+
// ------------------------------------------------------------------------
428+
public Filter isNull() {
429+
return isNull(true);
430+
}
431+
432+
public Filter isNotNull() {
433+
return isNull(false);
434+
}
435+
436+
public Filter isNull(boolean isNull) {
437+
return new Filter(Operator.IS_NULL, left, new BooleanOperand(isNull));
438+
}
439+
425440
// Like
426441
// ------------------------------------------------------------------------
427442
public Filter like(String value) {

0 commit comments

Comments
 (0)