Merge pull request #1295 from krunal1313/posting_list_iterator

Posting list iterator
This commit is contained in:
Kishore Nallan 2023-10-13 12:49:24 +05:30 committed by GitHub
commit 72adf3de8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 3 deletions

View File

@ -1289,9 +1289,6 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,
}
std::vector<group_by_field_it_t> group_by_field_it_vec;
if (group_limit != 0) {
group_by_field_it_vec = get_group_by_field_iterators(group_by_fields);
}
size_t total_docs = seq_ids->num_ids();
// assumed that facet fields have already been validated upstream
@ -1379,6 +1376,10 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,
posting_list_t::iterator_t facet_index_it = facet_index->new_iterator();
std::vector<uint32_t> facet_hashes;
if (group_limit != 0) {
group_by_field_it_vec = get_group_by_field_iterators(group_by_fields);
}
for(size_t i = 0; i < results_size; i++) {
// if sampling is enabled, we will skip a portion of the results to speed up things
if(estimate_facets) {

View File

@ -986,4 +986,63 @@ TEST_F(CollectionGroupingTest, SkipToReverseGroupBy) {
ASSERT_EQ("puma", res["grouped_hits"][2]["group_key"][0].get<std::string>());
ASSERT_EQ(1, res["grouped_hits"][2]["hits"].size());
}
TEST_F(CollectionGroupingTest, GroupByMultipleFacetFields) {
auto res = coll_group->search("*", {}, "", {"brand", "colors"}, {}, {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,
{}, {}, {"size"}, 2).get();
ASSERT_EQ(12, res["found_docs"].get<size_t>());
ASSERT_EQ(3, res["found"].get<size_t>());
ASSERT_EQ(3, res["grouped_hits"].size());
ASSERT_EQ(11, res["grouped_hits"][0]["group_key"][0].get<size_t>());
ASSERT_EQ(2, res["grouped_hits"][0]["found"].get<int32_t>());
ASSERT_FLOAT_EQ(4.8, res["grouped_hits"][0]["hits"][0]["document"]["rating"].get<float>());
ASSERT_EQ(11, res["grouped_hits"][0]["hits"][0]["document"]["size"].get<size_t>());
ASSERT_STREQ("5", res["grouped_hits"][0]["hits"][0]["document"]["id"].get<std::string>().c_str());
ASSERT_FLOAT_EQ(4.3, res["grouped_hits"][0]["hits"][1]["document"]["rating"].get<float>());
ASSERT_STREQ("1", res["grouped_hits"][0]["hits"][1]["document"]["id"].get<std::string>().c_str());
ASSERT_EQ(7, res["grouped_hits"][1]["found"].get<int32_t>());
ASSERT_FLOAT_EQ(4.8, res["grouped_hits"][1]["hits"][0]["document"]["rating"].get<float>());
ASSERT_STREQ("4", res["grouped_hits"][1]["hits"][0]["document"]["id"].get<std::string>().c_str());
ASSERT_FLOAT_EQ(4.6, res["grouped_hits"][1]["hits"][1]["document"]["rating"].get<float>());
ASSERT_STREQ("3", res["grouped_hits"][1]["hits"][1]["document"]["id"].get<std::string>().c_str());
ASSERT_EQ(3, res["grouped_hits"][2]["found"].get<int32_t>());
ASSERT_FLOAT_EQ(4.6, res["grouped_hits"][2]["hits"][0]["document"]["rating"].get<float>());
ASSERT_STREQ("2", res["grouped_hits"][2]["hits"][0]["document"]["id"].get<std::string>().c_str());
ASSERT_FLOAT_EQ(4.4, res["grouped_hits"][2]["hits"][1]["document"]["rating"].get<float>());
ASSERT_STREQ("8", res["grouped_hits"][2]["hits"][1]["document"]["id"].get<std::string>().c_str());
ASSERT_STREQ("brand", res["facet_counts"][0]["field_name"].get<std::string>().c_str());
ASSERT_EQ(3, (int) res["facet_counts"][0]["counts"][0]["count"]);
ASSERT_STREQ("Beta", res["facet_counts"][0]["counts"][0]["value"].get<std::string>().c_str());
ASSERT_EQ(3, (int) res["facet_counts"][0]["counts"][1]["count"]);
ASSERT_STREQ("Omega", res["facet_counts"][0]["counts"][1]["value"].get<std::string>().c_str());
ASSERT_EQ(2, (int) res["facet_counts"][0]["counts"][2]["count"]);
ASSERT_STREQ("Xorp", res["facet_counts"][0]["counts"][2]["value"].get<std::string>().c_str());
ASSERT_EQ(1, (int) res["facet_counts"][0]["counts"][3]["count"]);
ASSERT_STREQ("Zeta", res["facet_counts"][0]["counts"][3]["value"].get<std::string>().c_str());
ASSERT_STREQ("colors", res["facet_counts"][1]["field_name"].get<std::string>().c_str());
ASSERT_EQ(3, (int) res["facet_counts"][1]["counts"][0]["count"]);
ASSERT_STREQ("blue", res["facet_counts"][1]["counts"][0]["value"].get<std::string>().c_str());
ASSERT_EQ(3, (int) res["facet_counts"][1]["counts"][1]["count"]);
ASSERT_STREQ("white", res["facet_counts"][1]["counts"][1]["value"].get<std::string>().c_str());
ASSERT_EQ(1, (int) res["facet_counts"][1]["counts"][2]["count"]);
ASSERT_STREQ("red", res["facet_counts"][1]["counts"][2]["value"].get<std::string>().c_str());
}