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
35 changes: 3 additions & 32 deletions src/it/java/io/weaviate/integration/SearchITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ public void testFetchObjectsWithSort() throws Exception {

var numbers = client.collections.use(nsNumbers);

var one = numbers.data.insert(Map.of("value", 1L));
var two = numbers.data.insert(Map.of("value", 2L));
var three = numbers.data.insert(Map.of("value", 3L));
numbers.data.insert(Map.of("value", 1L));
numbers.data.insert(Map.of("value", 2L));
numbers.data.insert(Map.of("value", 3L));

// Act: sort ascending
var asc = numbers.query.fetchObjects(
Expand All @@ -294,35 +294,6 @@ public void testFetchObjectsWithSort() throws Exception {
.extracting(WeaviateObject::properties)
.extracting(object -> object.get("value"))
.containsExactly(3L, 2L, 1L);

// Act: sort by creation time asc
var created = numbers.query.fetchObjects(
q -> q.sort(SortBy.creationTime()));

Assertions.assertThat(created.objects())
.as("create time asc")
.hasSize(3)
.extracting(WeaviateObject::uuid)
.containsExactly(one.uuid(), two.uuid(), three.uuid());

// Act: sort by updated time desc
numbers.data.update(one.uuid(), upd -> upd.properties(Map.of("value", -1L)));
Thread.sleep(10);
numbers.data.update(two.uuid(), upd -> upd.properties(Map.of("value", -2L)));
Thread.sleep(10);
numbers.data.update(three.uuid(), upd -> upd.properties(Map.of("value", -3L)));

var updated = numbers.query.fetchObjects(
q -> q.sort(
// Both sort operators imply ordering 3-2-1
SortBy.lastUpdateTime().desc(),
SortBy.property("value").asc()));

Assertions.assertThat(updated.objects())
.as("last update time desc + value asc")
.hasSize(3)
.extracting(WeaviateObject::uuid)
.containsExactly(three.uuid(), two.uuid(), one.uuid());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ public static SortBy property(String property) {
return new SortBy(List.of(property), true);
}

/**
* Sort by object's UUID. Ascending order by default.
*
* <p>
* Sorting by UUID may be useful if objects are assigned
* custom UUIDv7 at ingestion, as those are "time-ordered".
*
* <p>
* It may be less useful for the auto-generated UUIDs,
* which will produce an essentialy random, albeit stable, order.
*
* @see #desc() to sort in descending order.
*/
public static SortBy uuid() {
return property(ById.ID_PROPERTY);
}

/**
* Sort by object creation time. Ascending order by default.
*
Expand Down