mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 22:33:27 +08:00
Facets: don't check contains before skipping.
This commit is contained in:
parent
d17d3356d1
commit
8b0c39d0f4
@ -1225,7 +1225,6 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,
|
||||
}
|
||||
|
||||
bool is_wildcard_no_filter_query = is_wildcard_query && no_filters_provided;
|
||||
bool facet_hash_index_exists = facet_index_v4->has_hash_index(facet_field.name);
|
||||
bool facet_value_index_exists = facet_index_v4->has_value_index(facet_field.name);
|
||||
|
||||
#ifdef TEST_BUILD
|
||||
@ -1258,9 +1257,8 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,
|
||||
const auto& searched_tokens = fquery_hashes_it->second;
|
||||
auto facet_str = kv.first;
|
||||
transform(facet_str.begin(), facet_str.end(), facet_str.begin(), ::tolower);
|
||||
|
||||
for(const auto& val : searched_tokens)
|
||||
{
|
||||
|
||||
for(const auto& val : searched_tokens) {
|
||||
if(facet_str.find(val) != std::string::npos) {
|
||||
facet_count_t& facet_count = a_facet.result_map[kv.first];
|
||||
facet_count.count = kv.second;
|
||||
@ -1284,14 +1282,11 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
facet_map_t::iterator facet_map_it;
|
||||
single_val_facet_map_t::iterator single_facet_map_it;
|
||||
|
||||
bool facet_hash_index_exists = facet_index_v4->has_hash_index(facet_field.name);
|
||||
if(!facet_hash_index_exists) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto sort_index_it = sort_index.find(a_facet.field_name);
|
||||
const auto facet_field_is_array = facet_field.is_array();
|
||||
|
||||
const auto& facet_index = facet_index_v4->get_facet_hash_index(facet_field.name);
|
||||
@ -1307,13 +1302,13 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,
|
||||
}
|
||||
|
||||
uint32_t doc_seq_id = result_ids[i];
|
||||
if(!facet_index->contains(doc_seq_id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
facet_index_it.skip_to(doc_seq_id);
|
||||
|
||||
if(facet_index_it.valid()) {
|
||||
if(facet_index_it.id() != doc_seq_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
facet_hashes.clear();
|
||||
posting_list_t::get_offsets(facet_index_it, facet_hashes);
|
||||
|
||||
|
@ -676,6 +676,24 @@ TEST_F(CollectionOptimizedFacetingTest, FacetCountOnSimilarStrings) {
|
||||
ASSERT_STREQ("India in England", results["facet_counts"][0]["counts"][0]["value"].get<std::string>().c_str());
|
||||
ASSERT_STREQ("England in India", results["facet_counts"][0]["counts"][1]["value"].get<std::string>().c_str());
|
||||
|
||||
// facet query
|
||||
results = coll1->search("*", {"categories"}, "points:[25, 50]", facets, sort_fields, {0}, 10, 1,
|
||||
token_ordering::FREQUENCY, {true}, 10, spp::sparse_hash_set<std::string>(),
|
||||
spp::sparse_hash_set<std::string>(), 10, "categories:india eng", 30UL, 4UL,
|
||||
"", 1UL, "", "", {}, 3UL, "<mark>", "</mark>", {},
|
||||
4294967295UL, true, false, true, "", false, 6000000UL, 4UL,
|
||||
7UL, fallback, 4UL, {off}, 32767UL, 32767UL, 2UL, 2UL, false,
|
||||
"", true, 0UL, max_score, 100UL, 0UL, 4294967295UL, VALUE).get();
|
||||
|
||||
ASSERT_EQ(2, results["hits"].size());
|
||||
ASSERT_EQ(2, results["facet_counts"][0]["counts"].size());
|
||||
|
||||
ASSERT_STREQ("India in England", results["facet_counts"][0]["counts"][0]["value"].get<std::string>().c_str());
|
||||
ASSERT_STREQ("<mark>India</mark> in <mark>Eng</mark>land", results["facet_counts"][0]["counts"][0]["highlighted"].get<std::string>().c_str());
|
||||
|
||||
ASSERT_STREQ("England in India", results["facet_counts"][0]["counts"][1]["value"].get<std::string>().c_str());
|
||||
ASSERT_STREQ("<mark>Eng</mark>land in <mark>India</mark>", results["facet_counts"][0]["counts"][1]["highlighted"].get<std::string>().c_str());
|
||||
|
||||
collectionManager.drop_collection("coll1");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user