Skip to content

Commit 653237f

Browse files
committed
feat: add SortBy.creationTime/lastUpdateTime
1 parent 8752941 commit 653237f

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public void testFetchObjectsWithFilters() throws IOException {
259259
}
260260

261261
@Test
262-
public void testFetchObjectsWithSort() throws IOException {
262+
public void testFetchObjectsWithSort() throws Exception {
263263
var nsNumbers = ns("Numbers");
264264

265265
// Arrange
@@ -277,6 +277,7 @@ public void testFetchObjectsWithSort() throws IOException {
277277
q -> q.sort(SortBy.property("value")));
278278

279279
Assertions.assertThat(asc.objects())
280+
.as("value asc")
280281
.hasSize(3)
281282
.extracting(WeaviateObject::properties)
282283
.extracting(object -> object.get("value"))
@@ -287,10 +288,40 @@ public void testFetchObjectsWithSort() throws IOException {
287288
q -> q.sort(SortBy.property("value").desc()));
288289

289290
Assertions.assertThat(desc.objects())
291+
.as("value desc")
290292
.hasSize(3)
291293
.extracting(WeaviateObject::properties)
292294
.extracting(object -> object.get("value"))
293295
.containsExactly(3L, 2L, 1L);
296+
297+
// Act: sort by creation time asc
298+
var created = numbers.query.fetchObjects(
299+
q -> q.sort(SortBy.creationTime()));
300+
301+
Assertions.assertThat(created.objects())
302+
.as("create time asc")
303+
.hasSize(3)
304+
.extracting(WeaviateObject::uuid)
305+
.containsExactly(one.uuid(), two.uuid(), three.uuid());
306+
307+
// Act: sort by updated time desc
308+
numbers.data.update(one.uuid(), upd -> upd.properties(Map.of("value", -1L)));
309+
Thread.sleep(10);
310+
numbers.data.update(two.uuid(), upd -> upd.properties(Map.of("value", -2L)));
311+
Thread.sleep(10);
312+
numbers.data.update(three.uuid(), upd -> upd.properties(Map.of("value", -3L)));
313+
314+
var updated = numbers.query.fetchObjects(
315+
q -> q.sort(
316+
// Both sort operators imply ordering 3-2-1
317+
SortBy.lastUpdateTime().desc(),
318+
SortBy.property("value").asc()));
319+
320+
Assertions.assertThat(updated.objects())
321+
.as("last update time desc + value asc")
322+
.hasSize(3)
323+
.extracting(WeaviateObject::uuid)
324+
.containsExactly(three.uuid(), two.uuid(), one.uuid());
294325
}
295326

296327
@Test

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ public static SortBy property(String property) {
77
return new SortBy(List.of(property), true);
88
}
99

10+
public static SortBy creationTime() {
11+
return property("_creationTimeUnix");
12+
}
13+
14+
public static SortBy lastUpdateTime() {
15+
return property("_lastUpdateTimeUnix");
16+
}
17+
1018
public SortBy asc() {
1119
return new SortBy(path, true);
1220
}

0 commit comments

Comments
 (0)