Skip to content

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

clean up

krunal1313ef05d420c96c
diff --git a/include/index.h b/include/index.h
index d56c610c..71f5ff72 100644
--- a/include/index.h
+++ b/include/index.h
@@ -190,7 +190,6 @@ struct search_args {
struct offsets_facet_hashes_t {
std::unordered_map<std::string, std::vector<uint32_t>> offsets;
- //std::vector<uint32_t> facet_hashes;
};
struct index_record {
diff --git a/src/facet_index.cpp b/src/facet_index.cpp
index 7875f091..99af1f35 100644
--- a/src/facet_index.cpp
+++ b/src/facet_index.cpp
@@ -14,7 +14,7 @@ uint32_t facet_index_t::insert(const std::string& field, const std::string& valu
fis.index = index;
facet_index_map.emplace(sv, fis);
}else {
- auto ids = facet_index_map[sv].id_list_ptr;
+ auto ids = it->id_list_ptr;
if (!ids_t::contains(ids, id)) {
ids_t::upsert(ids, id);
facet_index_map[sv].id_list_ptr = ids;
diff --git a/src/index.cpp b/src/index.cpp
index 99212649..b924727d 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -321,15 +321,15 @@ void Index::compute_token_offsets_facets(index_record& record,
if(the_field.type == field_types::STRING) {
tokenize_string_with_facets(document[field_name], is_facet, the_field,
local_symbols_to_index, local_token_separators,
- offset_facet_hashes.offsets/*, offset_facet_hashes.facet_hashes*/);
+ offset_facet_hashes.offsets);
} else {
tokenize_string_array_with_facets(document[field_name], is_facet, the_field,
local_symbols_to_index, local_token_separators,
- offset_facet_hashes.offsets/*, offset_facet_hashes.facet_hashes*/);
+ offset_facet_hashes.offsets);
}
}
- if(!offset_facet_hashes.offsets.empty() /*|| !offset_facet_hashes.facet_hashes.empty()*/) {
+ if(!offset_facet_hashes.offsets.empty()) {
record.field_index.emplace(field_name, std::move(offset_facet_hashes));
}
}
@@ -2864,7 +2864,6 @@ Option<bool> Index::search(std::vector<query_tokens_t>& field_query_tokens, cons
bool estimate_facets = (facet_sample_percent < 100 && all_result_ids_len > facet_sample_threshold);
if(!facets.empty()) {
- //const size_t num_threads = std::min(concurrency, all_result_ids_len);
const size_t num_threads = 1;
const size_t window_size = (num_threads == 0) ? 0 :
diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cpp
index c9436bbd..041c1f08 100644
--- a/test/collection_faceting_test.cpp
+++ b/test/collection_faceting_test.cpp
@@ -1610,58 +1610,3 @@ TEST_F(CollectionFacetingTest, FacetOnArrayFieldWithSpecialChars) {
}
}
}
-
-TEST_F(CollectionFacetingTest, FacetIndexRefactor) {
- Collection *coll_array_fields;
-
- std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
- std::vector<field> fields = {field("name", field_types::STRING, false),
- field("name_facet", field_types::STRING, true),
- field("age", field_types::INT32, true),
- field("years", field_types::INT32_ARRAY, true),
- field("rating", field_types::FLOAT, true),
- field("timestamps", field_types::INT64_ARRAY, true),
- field("tags", field_types::STRING_ARRAY, true)};
-
- std::vector<sort_by> sort_fields = { sort_by("age", "DESC") };
-
- coll_array_fields = collectionManager.get_collection("coll_array_fields").get();
- if(coll_array_fields == nullptr) {
- coll_array_fields = collectionManager.create_collection("coll_array_fields", 4, fields, "age").get();
- }
-
- std::string json_line;
-
- while (std::getline(infile, json_line)) {
- nlohmann::json document = nlohmann::json::parse(json_line);
- document["name_facet"] = document["name"];
- const std::string & patched_json_line = document.dump();
- coll_array_fields->add(patched_json_line);
- }
-
- infile.close();
-
- query_fields = {"name"};
- std::vector<std::string> facets = {"tags"};
-
- // single facet with no filters
- nlohmann::json results = coll_array_fields->search("Jeremy", query_fields, "", facets, sort_fields, {0}, 10, 1, FREQUENCY, {false}).get();
-
- ASSERT_EQ(5, results["hits"].size());
- ASSERT_EQ(1, results["facet_counts"].size());
- ASSERT_EQ(4, results["facet_counts"][0].size());
- ASSERT_EQ(4, results["facet_counts"][0]["counts"].size());
- ASSERT_EQ("tags", results["facet_counts"][0]["field_name"]);
-
- ASSERT_STREQ("gold", results["facet_counts"][0]["counts"][0]["value"].get<std::string>().c_str());
- ASSERT_EQ(3, (int) results["facet_counts"][0]["counts"][0]["count"]);
-
- ASSERT_STREQ("silver", results["facet_counts"][0]["counts"][1]["value"].get<std::string>().c_str());
- ASSERT_EQ(3, (int) results["facet_counts"][0]["counts"][1]["count"]);
-
- ASSERT_STREQ("bronze", results["facet_counts"][0]["counts"][2]["value"].get<std::string>().c_str());
- ASSERT_EQ(2, (int) results["facet_counts"][0]["counts"][2]["count"]);
-
- ASSERT_STREQ("FINE PLATINUM", results["facet_counts"][0]["counts"][3]["value"].get<std::string>().c_str());
- ASSERT_EQ(1, (int) results["facet_counts"][0]["counts"][3]["count"]);
-}
\ No newline at end of file