Merge branch 'v0.24.1' into v0.25

This commit is contained in:
Kishore Nallan 2023-02-20 18:10:49 +05:30
commit 3b2e7e22f2
4 changed files with 50 additions and 2 deletions

View File

@ -355,7 +355,7 @@ struct field {
}
}
if(!default_sorting_field.empty() && !found_default_sorting_field && !fields.empty()) {
if(!default_sorting_field.empty() && !found_default_sorting_field) {
return Option<bool>(400, "Default sorting field is defined as `" + default_sorting_field +
"` but is not found in the schema.");
}

View File

@ -817,7 +817,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 +

View File

@ -1145,6 +1145,10 @@ Option<Collection*> CollectionManager::create_collection(nlohmann::json& req_jso
const std::string& default_sorting_field = req_json[DEFAULT_SORTING_FIELD].get<std::string>();
if(default_sorting_field == "id") {
return Option<Collection *>(400, "Invalid `default_sorting_field` value: cannot be `id`.");
}
std::string fallback_field_type;
std::vector<field> fields;
auto parse_op = field::json_fields_to_fields(req_json[ENABLE_NESTED_FIELDS].get<bool>(),

View File

@ -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"(
{
@ -2147,6 +2173,23 @@ TEST_F(CollectionSortingTest, OptionalFilteringViaSortingSearch) {
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionSortingTest, DisallowIdAsDefaultSortingField) {
std::string coll_schema = R"(
{
"name": "coll1",
"default_sorting_field": "id",
"fields": [
{"name": "id", "type": "string" }
]
}
)";
nlohmann::json schema = nlohmann::json::parse(coll_schema);
auto coll_op = collectionManager.create_collection(schema);
ASSERT_FALSE(coll_op.ok());
ASSERT_EQ("Invalid `default_sorting_field` value: cannot be `id`.", coll_op.error());
}
TEST_F(CollectionSortingTest, OptionalFilteringViaSortingSecondThirdParams) {
std::string coll_schema = R"(
{