mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 20:52:50 +08:00
Allow sequence id based sorting.
This commit is contained in:
parent
5f4d43f877
commit
e80b17085a
@ -722,7 +722,8 @@ Option<bool> Collection::validate_and_standardize_sort_fields(const std::vector<
|
||||
}
|
||||
}
|
||||
|
||||
if (sort_field_std.name != sort_field_const::text_match && sort_field_std.name != sort_field_const::eval) {
|
||||
if (sort_field_std.name != sort_field_const::text_match && sort_field_std.name != sort_field_const::eval &&
|
||||
sort_field_std.name != sort_field_const::seq_id) {
|
||||
const auto field_it = search_schema.find(sort_field_std.name);
|
||||
if(field_it == search_schema.end() || !field_it.value().sort || !field_it.value().index) {
|
||||
std::string error = "Could not find a field named `" + sort_field_std.name +
|
||||
|
@ -1952,6 +1952,32 @@ TEST_F(CollectionSortingTest, DisallowSortingOnNonIndexedIntegerField) {
|
||||
collectionManager.drop_collection("coll1");
|
||||
}
|
||||
|
||||
TEST_F(CollectionSortingTest, WildcardSearchSequenceIdSort) {
|
||||
nlohmann::json schema = R"({
|
||||
"name": "coll1",
|
||||
"fields": [
|
||||
{"name": "category", "type": "string"}
|
||||
]
|
||||
})"_json;
|
||||
|
||||
Collection* coll1 = collectionManager.create_collection(schema).get();
|
||||
|
||||
nlohmann::json doc;
|
||||
doc["category"] = "Shoes";
|
||||
|
||||
for(size_t i = 0; i < 30; i++) {
|
||||
ASSERT_TRUE(coll1->add(doc.dump()).ok());
|
||||
}
|
||||
|
||||
std::vector<sort_by> sort_fields = {
|
||||
sort_by("_seq_id", "DESC"),
|
||||
};
|
||||
|
||||
auto res = coll1->search("*", {"category"}, "", {}, sort_fields, {2}, 10, 1, FREQUENCY, {true}, 0).get();
|
||||
ASSERT_EQ(10, res["hits"].size());
|
||||
ASSERT_EQ(30, res["found"].get<size_t>());
|
||||
}
|
||||
|
||||
TEST_F(CollectionSortingTest, OptionalFilteringViaSortingWildcard) {
|
||||
std::string coll_schema = R"(
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user