mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 22:33:27 +08:00
adding test for group sorting without group_by fields
This commit is contained in:
parent
c5d06cd271
commit
ff7f906081
@ -819,19 +819,18 @@ 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 &&
|
||||
sort_field_std.name != sort_field_const::seq_id) {
|
||||
if(!is_group_by_query) {
|
||||
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 +
|
||||
"` in the schema for sorting.";
|
||||
return Option<bool>(404, error);
|
||||
}
|
||||
sort_field_std.name != sort_field_const::seq_id && sort_field_std.name != sort_field_const::group_count) {
|
||||
|
||||
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 +
|
||||
"` in the schema for sorting.";
|
||||
return Option<bool>(404, error);
|
||||
}
|
||||
}
|
||||
|
||||
if(sort_field_std.name == sort_field_const::group_count && is_group_by_query == false) {
|
||||
std::string error = " group_by parameters should not be empty when using sort_by group_count";
|
||||
std::string error = "group_by parameters should not be empty when using sort_by group_count";
|
||||
return Option<bool>(404, error);
|
||||
}
|
||||
|
||||
|
@ -785,4 +785,19 @@ TEST_F(CollectionGroupingTest, SortingMoreThanMaxTopsterSize) {
|
||||
ASSERT_EQ(4, res2["grouped_hits"][50]["found"].get<int32_t>());
|
||||
|
||||
ASSERT_EQ(4, res2["grouped_hits"][99]["found"].get<int32_t>());
|
||||
}
|
||||
|
||||
TEST_F(CollectionGroupingTest, GroupSortingWithoutGroupingFields) {
|
||||
|
||||
std::vector<sort_by> sort_fields = {sort_by("_group_count", "DESC")};
|
||||
|
||||
auto res = coll_group->search("*", {}, "", {"brand"}, sort_fields, {0}, 50, 1, FREQUENCY,
|
||||
{false}, Index::DROP_TOKENS_THRESHOLD,
|
||||
spp::sparse_hash_set<std::string>(),
|
||||
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
|
||||
"", 10,
|
||||
{}, {}, {});
|
||||
|
||||
ASSERT_EQ(res.ok(), false);
|
||||
ASSERT_EQ(res.error(), "group_by parameters should not be empty when using sort_by group_count");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user