Skip to content

Commit 1374440

Browse files
committed
chore: document SortBy usage
1 parent a29ec19 commit 1374440

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,30 @@ public FetchObjects(Builder builder) {
2121
public static class Builder extends BaseQueryOptions.Builder<Builder, FetchObjects> {
2222
private final List<SortBy> sortBy = new ArrayList<>();
2323

24+
/**
25+
* Sort query results. Default sorted order is ascending, use
26+
* {@link SortBy#desc} to reverse it.
27+
*
28+
* <pre>{@code
29+
* sort(SortBy.property("age"), SortBy.creationTime().desc());
30+
* }</pre>
31+
*
32+
* @param sortBy A list of sort-by clauses in the order
33+
* they should be applied.
34+
* @return This builder.
35+
*/
2436
public Builder sort(SortBy... sortBy) {
2537
return sort(Arrays.asList(sortBy));
2638
}
2739

40+
/**
41+
* Sort query results. Default sorted order is ascending, use
42+
* {@link SortBy#desc} to reverse it.
43+
*
44+
* @param sortBy A list of sort-by clauses in the order
45+
* they should be applied.
46+
* @return This builder.
47+
*/
2848
public Builder sort(List<SortBy> sortBy) {
2949
this.sortBy.addAll(sortBy);
3050
return this;

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,57 @@
33
import java.util.List;
44

55
public record SortBy(List<String> path, boolean ascending) {
6+
/**
7+
* Sort by object property. Ascending order by default.
8+
*
9+
* @see #desc() to sort in descending order.
10+
*/
611
public static SortBy property(String property) {
712
return new SortBy(List.of(property), true);
813
}
914

15+
/**
16+
* Sort by object creation time. Ascending order by default.
17+
*
18+
* @see #desc() to sort in descending order.
19+
*/
1020
public static SortBy creationTime() {
1121
return property("_creationTimeUnix");
1222
}
1323

24+
/**
25+
* Sort by object last update time. Ascending order by default.
26+
*
27+
* @see #desc() to sort in descending order.
28+
*/
1429
public static SortBy lastUpdateTime() {
1530
return property("_lastUpdateTimeUnix");
1631
}
1732

33+
/**
34+
* Sort in ascending order.
35+
*
36+
* <p>
37+
* Example:
38+
*
39+
* <pre>{@code
40+
* SortBy.property("name").asc();
41+
* }</pre>
42+
*/
1843
public SortBy asc() {
1944
return new SortBy(path, true);
2045
}
2146

47+
/**
48+
* Sort in descending order.
49+
*
50+
* <p>
51+
* Example:
52+
*
53+
* <pre>{@code
54+
* SortBy.property("name").desc();
55+
* }</pre>
56+
*/
2257
public SortBy desc() {
2358
return new SortBy(path, false);
2459
}

0 commit comments

Comments
 (0)