Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
updating changes
krunal0f73648534cc
diff --git a/include/facet_index.h b/include/facet_index.hindex 20bdab66..33ad924e 100644--- a/include/facet_index.h+++ b/include/facet_index.h@@ -111,7 +111,7 @@ private:// field -> facet_indexstd::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);};\ No newline at end of filediff --git a/src/facet_index.cpp b/src/facet_index.cppindex c28d7326..ff519fe5 100644--- a/src/facet_index.cpp+++ b/src/facet_index.cpp@@ -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_namreturn 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\ No newline at end of file+ const auto& facet_index = facet_field_map_it->second;+ return facet_index.fhash_to_int64_map;+}\ No newline at end of filediff --git a/src/index.cpp b/src/index.cppindex 3903d357..3b68cef9 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -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);diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cppindex 75d07e53..4ff66550 100644--- a/test/collection_faceting_test.cpp+++ b/test/collection_faceting_test.cpp@@ -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());}\ No newline at end of file