Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ songs.query.hybrid(
Objects can be filtered by property or reference values. In the latter case you need to pass the "path" to the property in the referenced collection.

```java
.where(Where.property("year").gte(1969))
.where(Where.reference("hasAwards", "GrammyAwards", "category").eq("New Artist"))
.filters(Filter.property("year").gte(1969))
.filters(Filter.reference("hasAwards", "GrammyAwards", "category").eq("New Artist"))
```

Supported **comparison operators**:
Expand All @@ -451,15 +451,15 @@ Supported **comparison operators**:
Comparison operators can be grouped using **logical operators** with arbitrarily deep nesting.

```java
.where(
Where.or(
Where.and(
Where.property("year").gt(2000),
Where.property("year").lt(2017)
.filters(
Filter.or(
Filter.and(
Filter.property("year").gt(2000),
Filter.property("year").lt(2017)
),
Where.or(
Where.property("artist").like("Boys"),
Where.property("genres").containsAny("#rock", "#rocknroll", "#grunge")
Filter.or(
Filter.property("artist").like("Boys"),
Filter.property("genres").containsAny("#rock", "#rocknroll", "#grunge")
)
)
)
Expand All @@ -471,23 +471,23 @@ Supported **logical operators**:
- Or: `.or`
- Not: `.not`

Operators passed in subsequent calls to `.where` are concatenated with the `.and` operartor.
Operators passed in subsequent calls to `.filters` are concatenated with the `.and` operartor.
These 3 calls are equivalent:

```java
.where(Where.and(cond1, cond2))
.where(cond1, cond2)
.where(cond1).where(cond2)
.filters(Filter.and(cond1, cond2))
.filters(cond1, cond2)
.filters(cond1).filters(cond2)
```

To negate an operator, wrap it in `Where.not(...)` or use the negation shorthand.
To negate an operator, wrap it in `Filter.not(...)` or use the negation shorthand.

```java
Where.not(Where.property("title").like("summer"));
Where.property("title").like("summer").not();
Filter.not(Filter.property("title").like("summer"));
Filter.property("title").like("summer").not();
```

Passing `null` and and empty `Where[]` to any of the logical operators as well as to the `.where()` method is safe -- the empty operators will simply be ignored.
Passing `null` and empty `Filter[]` to any of the logical operators as well as to the `.filters()` method is safe -- the empty operators will simply be ignored.


#### Grouping results
Expand Down
6 changes: 3 additions & 3 deletions src/it/java/io/weaviate/integration/DataITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import io.weaviate.client6.v1.api.collections.query.Metadata.MetadataField;
import io.weaviate.client6.v1.api.collections.query.QueryMetadata;
import io.weaviate.client6.v1.api.collections.query.QueryReference;
import io.weaviate.client6.v1.api.collections.query.Where;
import io.weaviate.client6.v1.api.collections.query.Filter;
import io.weaviate.containers.Container;

public class DataITest extends ConcurrentTest {
Expand Down Expand Up @@ -303,7 +303,7 @@ public void testDeleteMany() throws IOException {

// Act (dry run)
things.data.deleteMany(
Where.property("last_used").gte(4),
Filter.property("last_used").gte(4),
opt -> opt.dryRun(true));

// Assert
Expand All @@ -312,7 +312,7 @@ public void testDeleteMany() throws IOException {

// Act (live run)
var deleted = things.data.deleteMany(
Where.property("last_used").gte(4),
Filter.property("last_used").gte(4),
opt -> opt.verbose(true));

// Assert
Expand Down
4 changes: 2 additions & 2 deletions src/it/java/io/weaviate/integration/ORMITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.weaviate.client6.v1.api.collections.annotations.Collection;
import io.weaviate.client6.v1.api.collections.annotations.Property;
import io.weaviate.client6.v1.api.collections.data.InsertManyResponse.InsertObject;
import io.weaviate.client6.v1.api.collections.query.Where;
import io.weaviate.client6.v1.api.collections.query.Filter;
import io.weaviate.containers.Container;

public class ORMITest extends ConcurrentTest {
Expand Down Expand Up @@ -318,7 +318,7 @@ public void test_insertManyAndQuery() throws Exception {

// Assert
var uuids = inserted.responses().stream().map(InsertObject::uuid).toArray(String[]::new);
var got = things.query.fetchObjects(q -> q.where(Where.uuid().containsAny(uuids)));
var got = things.query.fetchObjects(q -> q.filters(Filter.uuid().containsAny(uuids)));
Assertions.assertThat(got.objects())
.hasSize(3)
.usingRecursiveComparison(COMPARISON_CONFIG)
Expand Down
14 changes: 7 additions & 7 deletions src/it/java/io/weaviate/integration/SearchITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import io.weaviate.client6.v1.api.collections.query.QueryResponseGroup;
import io.weaviate.client6.v1.api.collections.query.SortBy;
import io.weaviate.client6.v1.api.collections.query.Target;
import io.weaviate.client6.v1.api.collections.query.Where;
import io.weaviate.client6.v1.api.collections.query.Filter;
import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw;
import io.weaviate.client6.v1.api.collections.vectorindex.MultiVector;
import io.weaviate.containers.Container;
Expand Down Expand Up @@ -251,12 +251,12 @@ public void testFetchObjectsWithFilters() throws IOException {
var hugeHat = hats.data.insert(Map.of("colour", "orange", "size", 40));

var got = hats.query.fetchObjects(
query -> query.where(
Where.or(
Where.property("colour").eq("orange"),
Where.and(
Where.property("size").gte(1),
Where.property("size").lt(6)))));
query -> query.filters(
Filter.or(
Filter.property("colour").eq("orange"),
Filter.and(
Filter.property("size").gte(1),
Filter.property("size").lt(6)))));

Assertions.assertThat(got.objects())
.extracting(hat -> hat.metadata().uuid())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.function.Function;

import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults;
import io.weaviate.client6.v1.api.collections.query.Where;
import io.weaviate.client6.v1.api.collections.query.Filter;
import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.grpc.ByteStringUtil;
import io.weaviate.client6.v1.internal.grpc.Rpc;
Expand All @@ -13,7 +13,7 @@
import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoBatchDelete;
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;

public record DeleteManyRequest(Where where, Boolean verbose, Boolean dryRun) {
public record DeleteManyRequest(Filter filters, Boolean verbose, Boolean dryRun) {

public static Rpc<DeleteManyRequest, WeaviateProtoBatchDelete.BatchDeleteRequest, DeleteManyResponse, WeaviateProtoBatchDelete.BatchDeleteReply> rpc(
CollectionDescriptor<?> collection,
Expand All @@ -37,7 +37,7 @@ public static Rpc<DeleteManyRequest, WeaviateProtoBatchDelete.BatchDeleteRequest
}

var filters = WeaviateProtoBase.Filters.newBuilder();
request.where.appendTo(filters);
request.filters.appendTo(filters);
message.setFilters(filters);

return message.build();
Expand All @@ -62,30 +62,30 @@ public static Rpc<DeleteManyRequest, WeaviateProtoBatchDelete.BatchDeleteRequest
() -> WeaviateFutureStub::batchDelete);
}

public static DeleteManyRequest of(Where where) {
return of(where, ObjectBuilder.identity());
public static DeleteManyRequest of(Filter filters) {
return of(filters, ObjectBuilder.identity());
}

public DeleteManyRequest(Builder builder) {
this(
builder.where,
builder.filters,
builder.verbose,
builder.dryRun);
}

public static DeleteManyRequest of(Where where, Function<Builder, ObjectBuilder<DeleteManyRequest>> fn) {
return fn.apply(new Builder(where)).build();
public static DeleteManyRequest of(Filter filters, Function<Builder, ObjectBuilder<DeleteManyRequest>> fn) {
return fn.apply(new Builder(filters)).build();
}

public static class Builder implements ObjectBuilder<DeleteManyRequest> {
// Required request parameters;
private final Where where;
private final Filter filters;

private Boolean verbose;
private Boolean dryRun;

public Builder(Where where) {
this.where = where;
public Builder(Filter filters) {
this.filters = filters;
}

public Builder verbose(boolean verbose) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import io.weaviate.client6.v1.api.collections.ObjectMetadata;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClient;
import io.weaviate.client6.v1.api.collections.query.Where;
import io.weaviate.client6.v1.api.collections.query.WhereOperand;
import io.weaviate.client6.v1.api.collections.query.Filter;
import io.weaviate.client6.v1.api.collections.query.FilterOperand;
import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.grpc.GrpcTransport;
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;
Expand Down Expand Up @@ -104,18 +104,18 @@ public void delete(String uuid) throws IOException {

public DeleteManyResponse deleteMany(String... uuids) {
var either = Arrays.stream(uuids)
.map(uuid -> (WhereOperand) Where.uuid().eq(uuid))
.map(uuid -> (FilterOperand) Filter.uuid().eq(uuid))
.toList();
return deleteMany(DeleteManyRequest.of(Where.or(either)));
return deleteMany(DeleteManyRequest.of(Filter.or(either)));
}

public DeleteManyResponse deleteMany(Where where) {
return deleteMany(DeleteManyRequest.of(where));
public DeleteManyResponse deleteMany(Filter filters) {
return deleteMany(DeleteManyRequest.of(filters));
}

public DeleteManyResponse deleteMany(Where where,
public DeleteManyResponse deleteMany(Filter filters,
Function<DeleteManyRequest.Builder, ObjectBuilder<DeleteManyRequest>> fn) {
return deleteMany(DeleteManyRequest.of(where, fn));
return deleteMany(DeleteManyRequest.of(filters, fn));
}

public DeleteManyResponse deleteMany(DeleteManyRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import io.weaviate.client6.v1.api.collections.ObjectMetadata;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClientAsync;
import io.weaviate.client6.v1.api.collections.query.Where;
import io.weaviate.client6.v1.api.collections.query.WhereOperand;
import io.weaviate.client6.v1.api.collections.query.Filter;
import io.weaviate.client6.v1.api.collections.query.FilterOperand;
import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.grpc.GrpcTransport;
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;
Expand Down Expand Up @@ -99,18 +99,18 @@ public CompletableFuture<Void> delete(String uuid) {

public CompletableFuture<DeleteManyResponse> deleteMany(String... uuids) {
var either = Arrays.stream(uuids)
.map(uuid -> (WhereOperand) Where.uuid().eq(uuid))
.map(uuid -> (FilterOperand) Filter.uuid().eq(uuid))
.toList();
return deleteMany(DeleteManyRequest.of(Where.or(either)));
return deleteMany(DeleteManyRequest.of(Filter.or(either)));
}

public CompletableFuture<DeleteManyResponse> deleteMany(Where where) {
return deleteMany(DeleteManyRequest.of(where));
public CompletableFuture<DeleteManyResponse> deleteMany(Filter filters) {
return deleteMany(DeleteManyRequest.of(filters));
}

public CompletableFuture<DeleteManyResponse> deleteMany(Where where,
public CompletableFuture<DeleteManyResponse> deleteMany(Filter filters,
Function<DeleteManyRequest.Builder, ObjectBuilder<DeleteManyRequest>> fn) {
return deleteMany(DeleteManyRequest.of(where, fn));
return deleteMany(DeleteManyRequest.of(filters, fn));
}

public CompletableFuture<DeleteManyResponse> deleteMany(DeleteManyRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import io.weaviate.client6.v1.api.collections.query.QueryMetadata;
import io.weaviate.client6.v1.api.collections.query.QueryReference;
import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClient;
import io.weaviate.client6.v1.api.collections.query.Where;
import io.weaviate.client6.v1.api.collections.query.Filter;
import io.weaviate.client6.v1.internal.ObjectBuilder;

public class Paginator<PropertiesT> implements Iterable<WeaviateObject<PropertiesT, Object, QueryMetadata>> {
Expand Down Expand Up @@ -90,8 +90,8 @@ public Builder<T> fromCursor(String uuid) {
// Query options ----------------------------------------------------------

/** Combine several conditions using with an AND operator. */
public final Builder<T> where(Where... where) {
return applyQueryOption(q -> q.where(where));
public final Builder<T> filters(Filter... filters) {
return applyQueryOption(q -> q.filters(filters));
}

public final Builder<T> returnProperties(String... properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public record BaseQueryOptions(
Integer autolimit,
String after,
ConsistencyLevel consistencyLevel,
Where where,
Filter filters,
GenerativeSearch generativeSearch,
List<String> returnProperties,
List<QueryReference> returnReferences,
Expand All @@ -33,7 +33,7 @@ private <T extends Object> BaseQueryOptions(Builder<? extends Builder<?, T>, T>
builder.autolimit,
builder.after,
builder.consistencyLevel,
builder.where,
builder.filter,
builder.generativeSearch,
builder.returnProperties,
builder.returnReferences,
Expand All @@ -49,7 +49,7 @@ public static abstract class Builder<SelfT extends Builder<SelfT, T>, T extends
private Integer autolimit;
private String after;
private ConsistencyLevel consistencyLevel;
private Where where;
private Filter filter;
private GenerativeSearch generativeSearch;
private List<String> returnProperties = new ArrayList<>();
private List<QueryReference> returnReferences = new ArrayList<>();
Expand Down Expand Up @@ -124,16 +124,16 @@ protected SelfT generate(Function<GenerativeSearch.Builder, ObjectBuilder<Genera
/**
* Filter result set using traditional filtering operators: {@code eq},
* {@code gte}, {@code like}, etc.
* Subsequent calls to {@link #where} aggregate with an AND operator.
* Subsequent calls to {@link #filter} aggregate with an AND operator.
*/
public final SelfT where(Where where) {
this.where = this.where == null ? where : Where.and(this.where, where);
public final SelfT filters(Filter filter) {
this.filter = this.filter == null ? filter : Filter.and(this.filter, filter);
return (SelfT) this;
}

/** Combine several conditions using with an AND operator. */
public final SelfT where(Where... wheres) {
Arrays.stream(wheres).map(this::where);
public final SelfT filters(Filter... filters) {
Arrays.stream(filters).map(this::filters);
return (SelfT) this;
}

Expand Down Expand Up @@ -218,9 +218,9 @@ final void appendTo(WeaviateProtoSearchGet.SearchRequest.Builder req) {
consistencyLevel.appendTo(req);
}

if (where != null) {
if (filters != null) {
var filter = WeaviateProtoBase.Filters.newBuilder();
where.appendTo(filter);
filters.appendTo(filter);
req.setFilters(filter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public FetchObjectById build() {

@Override
public void appendTo(WeaviateProtoSearchGet.SearchRequest.Builder req) {
var where = Where.uuid().eq(uuid);
var filters = Filter.uuid().eq(uuid);
var filter = WeaviateProtoBase.Filters.newBuilder();
where.appendTo(filter);
filters.appendTo(filter);
req.setFilters(filter);

var metadata = WeaviateProtoSearchGet.MetadataRequest.newBuilder();
Expand Down
Loading