|
1 | 1 | package io.weaviate.client6.v1.api.collections.aggregate; |
2 | 2 |
|
| 3 | +import java.util.function.Function; |
| 4 | + |
| 5 | +import io.weaviate.client6.v1.internal.ObjectBuilder; |
3 | 6 | import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoAggregate; |
4 | 7 |
|
5 | | -public record GroupBy(String property) { |
6 | | - public static final GroupBy of(String property) { |
7 | | - return new GroupBy(property); |
| 8 | +public record GroupBy(String property, Integer limit) { |
| 9 | + public static final GroupBy property(String property) { |
| 10 | + return property(property, ObjectBuilder.identity()); |
| 11 | + } |
| 12 | + |
| 13 | + public static final GroupBy property(String property, Function<Builder, ObjectBuilder<GroupBy>> fn) { |
| 14 | + return fn.apply(new Builder(property)).build(); |
| 15 | + } |
| 16 | + |
| 17 | + public GroupBy(Builder builder) { |
| 18 | + this(builder.property, builder.limit); |
| 19 | + } |
| 20 | + |
| 21 | + public static class Builder implements ObjectBuilder<GroupBy> { |
| 22 | + private final String property; |
| 23 | + |
| 24 | + public Builder(String property) { |
| 25 | + this.property = property; |
| 26 | + } |
| 27 | + |
| 28 | + private Integer limit; |
| 29 | + |
| 30 | + public final Builder limit(int limit) { |
| 31 | + this.limit = limit; |
| 32 | + return this; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public GroupBy build() { |
| 37 | + return new GroupBy(this); |
| 38 | + } |
8 | 39 | } |
9 | 40 |
|
10 | 41 | void appendTo(WeaviateProtoAggregate.AggregateRequest.Builder req, String collection) { |
| 42 | + if (limit != null) { |
| 43 | + req.setLimit(limit); |
| 44 | + } |
| 45 | + |
11 | 46 | req.setGroupBy(WeaviateProtoAggregate.AggregateRequest.GroupBy.newBuilder() |
12 | 47 | .setCollection(collection) |
13 | 48 | .setProperty(property)); |
|
0 commit comments