From cf1a54522f60f53e66a591c7893dab27231d95a6 Mon Sep 17 00:00:00 2001 From: krunal1313 Date: Tue, 2 May 2023 14:18:48 +0530 Subject: [PATCH] enabling filtering with new facet index --- src/index.cpp | 2 +- test/collection_optimized_faceting_test.cpp | 38 ++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/index.cpp b/src/index.cpp index bccc27b4..9eccc0f7 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -1232,7 +1232,7 @@ void Index::do_facets(std::vector & facets, facet_query_t & facet_query, #endif if(results_size && facet_records && ((facet_records <= 10 || is_wildcard_query) && - !use_facet_query && group_limit == 0 && no_filters_provided) + !use_facet_query && group_limit == 0) && !use_hashes || use_facet_intersection) { //LOG(INFO) << "Using intersection to find facets"; a_facet.is_intersected = true; diff --git a/test/collection_optimized_faceting_test.cpp b/test/collection_optimized_faceting_test.cpp index 6e14774b..7244d54e 100644 --- a/test/collection_optimized_faceting_test.cpp +++ b/test/collection_optimized_faceting_test.cpp @@ -185,6 +185,42 @@ TEST_F(CollectionOptimizedFacetingTest, FacetCounts) { facets.clear(); facets.push_back("tags"); + + results = coll_array_fields->search("*", query_fields, "age: >24", facets, sort_fields, {0}, 10, 1, FREQUENCY, + {false}, Index::DROP_TOKENS_THRESHOLD, + spp::sparse_hash_set(), + spp::sparse_hash_set(), 10, "", 30UL, 4UL, + "", 1UL, "", "", {}, 3UL, "", "", {}, + 4294967295UL, true, false, true, "", false, 6000000UL, 4UL, + 7UL, fallback, 4UL, {off}, 32767UL, 32767UL, 2UL, 2UL, false, + "", true, 0UL, max_score, 100UL, 0UL, 4294967295UL, true).get(); + + ASSERT_EQ(3, results["hits"].size()); + ASSERT_EQ(1, results["facet_counts"].size()); + + ASSERT_STREQ("tags", results["facet_counts"][0]["field_name"].get().c_str()); + ASSERT_EQ(2, (int) results["facet_counts"][0]["counts"][0]["count"]); + ASSERT_EQ(1, (int) results["facet_counts"][0]["counts"][1]["count"]); + ASSERT_EQ(1, (int) results["facet_counts"][0]["counts"][2]["count"]); + ASSERT_EQ(1, (int) results["facet_counts"][0]["counts"][3]["count"]); + + ASSERT_STREQ("silver", results["facet_counts"][0]["counts"][0]["value"].get().c_str()); + ASSERT_STREQ("gold", results["facet_counts"][0]["counts"][1]["value"].get().c_str()); + ASSERT_STREQ("bronze", results["facet_counts"][0]["counts"][2]["value"].get().c_str()); + ASSERT_STREQ("FINE PLATINUM", results["facet_counts"][0]["counts"][3]["value"].get().c_str()); + + // facet with wildcard + results = coll_array_fields->search("Jeremy", query_fields, "", {"ag*"}, sort_fields, {0}, 10, 1, FREQUENCY, + {false}, Index::DROP_TOKENS_THRESHOLD, + spp::sparse_hash_set(), + spp::sparse_hash_set(), 10, "", 30UL, 4UL, + "", 1UL, "", "", {}, 3UL, "", "", {}, + 4294967295UL, true, false, true, "", false, 6000000UL, 4UL, + 7UL, fallback, 4UL, {off}, 32767UL, 32767UL, 2UL, 2UL, false, + "", true, 0UL, max_score, 100UL, 0UL, 4294967295UL, true).get(); + ASSERT_EQ(5, results["hits"].size()); + ASSERT_EQ(1, results["facet_counts"].size()); + ASSERT_STREQ("age", results["facet_counts"][0]["field_name"].get().c_str()); // empty facet query value should return all facets without any filtering of facets results = coll_array_fields->search("*", query_fields, "", facets, sort_fields, {0}, 10, 1, FREQUENCY, @@ -515,7 +551,7 @@ TEST_F(CollectionOptimizedFacetingTest, FacetCountOnSimilarStrings) { std::vector facets = {"categories"}; - nlohmann::json results = coll1->search("*", {"categories"}, "", facets, sort_fields, {0}, 10, 1, + nlohmann::json results = coll1->search("*", {"categories"}, "points:[25, 50]", facets, sort_fields, {0}, 10, 1, token_ordering::FREQUENCY, {true}, 10, spp::sparse_hash_set(), spp::sparse_hash_set(), 10, "", 30UL, 4UL, "", 1UL, "", "", {}, 3UL, "", "", {},