mirror of
https://github.com/typesense/typesense.git
synced 2025-05-20 21:52:23 +08:00
updating changes
This commit is contained in:
parent
d1aef324a9
commit
0f73648534
@ -111,7 +111,7 @@ private:
|
||||
// field -> facet_index
|
||||
std::unordered_map<std::string, facet_doc_ids_list_t> facet_field_map;
|
||||
// auto incrementing ID that is assigned to each unique facet value string
|
||||
uint32_t next_facet_id = 0;
|
||||
std::atomic_uint32_t next_facet_id = 0;
|
||||
|
||||
public:
|
||||
|
||||
@ -152,10 +152,6 @@ public:
|
||||
|
||||
posting_list_t* get_facet_hash_index(const std::string& field_name);
|
||||
|
||||
//get int64 val from index for stats
|
||||
int64_t get_facet_val(const std::string& field_name, uint32_t index);
|
||||
|
||||
#ifdef TEST_BUILD
|
||||
size_t get_fhash_int64_map_count(const std::string& field_name);
|
||||
#endif
|
||||
//get fhash=>int64 map for stats
|
||||
const spp::sparse_hash_map<uint32_t, int64_t>& get_fhash_int64_map(const std::string& field_name);
|
||||
};
|
@ -132,9 +132,7 @@ void facet_index_t::remove(const std::string& field_name, const uint32_t seq_id)
|
||||
auto& fhash_int64_map = facet_field_it->second.fhash_to_int64_map;
|
||||
uint32_t fhash = facet_ids_seq_ids->second.facet_id;
|
||||
|
||||
if(fhash_int64_map.find(fhash) != fhash_int64_map.end()) {
|
||||
fhash_int64_map.erase(fhash);
|
||||
}
|
||||
fhash_int64_map.erase(fhash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -346,30 +344,12 @@ posting_list_t* facet_index_t::get_facet_hash_index(const std::string &field_nam
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int64_t facet_index_t::get_facet_val(const std::string& field_name, uint32_t index) {
|
||||
const spp::sparse_hash_map<uint32_t , int64_t >& facet_index_t::get_fhash_int64_map(const std::string& field_name) {
|
||||
const auto facet_field_map_it = facet_field_map.find(field_name);
|
||||
if(facet_field_map_it == facet_field_map.end()) {
|
||||
return INT64_MAX; // field is not initialized or dropped
|
||||
return spp::sparse_hash_map<uint32_t , int64_t >{}; // field is not initialized or dropped
|
||||
}
|
||||
|
||||
auto& facet_index = facet_field_map_it->second;
|
||||
|
||||
auto it = facet_index.fhash_to_int64_map.find(index);
|
||||
|
||||
if(it != facet_index.fhash_to_int64_map.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return INT64_MAX;
|
||||
}
|
||||
|
||||
#ifdef TEST_BUILD
|
||||
size_t facet_index_t::get_fhash_int64_map_count(const std::string& field_name) {
|
||||
const auto facet_field_map_it = facet_field_map.find(field_name);
|
||||
if(facet_field_map_it == facet_field_map.end()) {
|
||||
return 0; // field is not initialized or dropped
|
||||
}
|
||||
|
||||
return facet_field_map_it->second.fhash_to_int64_map.size();
|
||||
}
|
||||
#endif
|
||||
const auto& facet_index = facet_field_map_it->second;
|
||||
return facet_index.fhash_to_int64_map;
|
||||
}
|
@ -1337,6 +1337,8 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& fhash_int64_map = facet_index_v4->get_fhash_int64_map(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);
|
||||
@ -1386,7 +1388,11 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,
|
||||
if(should_compute_stats) {
|
||||
int64_t val = fhash;
|
||||
if(facet_field.is_int64()) {
|
||||
val = facet_index_v4->get_facet_val(a_facet.field_name,fhash);
|
||||
if(fhash_int64_map.find(fhash) != fhash_int64_map.end()) {
|
||||
val = fhash_int64_map.at(fhash);
|
||||
} else {
|
||||
val = INT64_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
compute_facet_stats(a_facet, val, facet_field.type);
|
||||
|
@ -2424,10 +2424,10 @@ TEST_F(CollectionFacetingTest, FhashInt64MapTest) {
|
||||
}
|
||||
|
||||
facet_index_v4.insert("visitors", fvalue_to_seq_ids, seq_id_to_fvalues);
|
||||
ASSERT_EQ(3, facet_index_v4.get_fhash_int64_map_count("visitors"));
|
||||
ASSERT_EQ(3, facet_index_v4.get_fhash_int64_map("visitors").size());
|
||||
|
||||
facet_index_v4.remove("visitors", 0);
|
||||
ASSERT_EQ(2, facet_index_v4.get_fhash_int64_map_count("visitors"));
|
||||
ASSERT_EQ(2, facet_index_v4.get_fhash_int64_map("visitors").size());
|
||||
|
||||
fvalue_to_seq_ids.clear();
|
||||
seq_id_to_fvalues.clear();
|
||||
@ -2437,5 +2437,5 @@ TEST_F(CollectionFacetingTest, FhashInt64MapTest) {
|
||||
seq_id_to_fvalues[seq_id].push_back(facet_value_id);
|
||||
|
||||
facet_index_v4.insert("visitors", fvalue_to_seq_ids, seq_id_to_fvalues);
|
||||
ASSERT_EQ(3, facet_index_v4.get_fhash_int64_map_count("visitors"));
|
||||
ASSERT_EQ(3, facet_index_v4.get_fhash_int64_map("visitors").size());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user