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

Increase max length of facet value stored.

Kishore Nallanb3db94867fbd
diff --git a/include/facet_index.h b/include/facet_index.h
index bb72b442..9e426a34 100644
--- a/include/facet_index.h
+++ b/include/facet_index.h
@@ -63,6 +63,9 @@ public:
uint32_t count;
uint32_t facet_id;
};
+
+ const static size_t MAX_FACET_VAL_LEN = 255;
+
private:
struct facet_id_seq_ids_t {
void* seq_ids;
diff --git a/src/index.cpp b/src/index.cpp
index b504c0c5..8d206375 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -746,7 +746,8 @@ void Index::index_field_in_memory(const field& afield, std::vector<index_record>
fvalue_to_seq_ids[facet_value_id].push_back(seq_id);
seq_id_to_fvalues[seq_id].push_back(facet_value_id);
} else if(afield.type == field_types::STRING_ARRAY) {
- const std::string& raw_val = field_values[i].get<std::string>().substr(0, 100);
+ const std::string& raw_val =
+ field_values[i].get<std::string>().substr(0, facet_index_t::MAX_FACET_VAL_LEN);
facet_value_id_t facet_value_id(raw_val);
fvalue_to_seq_ids[facet_value_id].push_back(seq_id);
seq_id_to_fvalues[seq_id].push_back(facet_value_id);
@@ -780,7 +781,8 @@ void Index::index_field_in_memory(const field& afield, std::vector<index_record>
seq_id_to_fvalues[seq_id].push_back(facet_value_id);
}
else if(afield.type == field_types::STRING) {
- const std::string& raw_val = document[afield.name].get<std::string>().substr(0, 100);
+ const std::string& raw_val =
+ document[afield.name].get<std::string>().substr(0, facet_index_t::MAX_FACET_VAL_LEN);
facet_value_id_t facet_value_id(raw_val);
fvalue_to_seq_ids[facet_value_id].push_back(seq_id);
seq_id_to_fvalues[seq_id].push_back(facet_value_id);
diff --git a/test/collection_optimized_faceting_test.cpp b/test/collection_optimized_faceting_test.cpp
index 2dad906a..b199863f 100644
--- a/test/collection_optimized_faceting_test.cpp
+++ b/test/collection_optimized_faceting_test.cpp
@@ -1688,11 +1688,11 @@ TEST_F(CollectionOptimizedFacetingTest, StringLengthTest) {
ASSERT_TRUE(coll1->add(doc.dump()).ok());
std::string longStr = "";
- for(auto i = 0; i < 8; ++i) {
+ for(auto i = 0; i < 20; ++i) {
longStr+="alphabetagamma";
}
- ASSERT_TRUE(112 == longStr.size());
+ ASSERT_TRUE(280 == longStr.size());
std::vector<std::string> vec;
vec.emplace_back(longStr);
@@ -1712,8 +1712,8 @@ TEST_F(CollectionOptimizedFacetingTest, StringLengthTest) {
longStr = results["facet_counts"][0]["counts"][3]["value"];
- //string facet length is restricted to 100
- ASSERT_TRUE(100 == longStr.size());
+ //string facet length is restricted to 255
+ ASSERT_EQ(255, longStr.size());
}
TEST_F(CollectionOptimizedFacetingTest, FacetingReturnParent) {