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
allow special char in range facet labels (#1760)
Krunal Gandhi94af3afb66ae
diff --git a/src/collection.cpp b/src/collection.cppindex 9d09dd74..6bab40d8 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -6262,7 +6262,7 @@ bool Collection::get_enable_nested_fields() {Option<bool> Collection::parse_facet(const std::string& facet_field, std::vector<facet>& facets) const {const std::regex base_pattern(".+\\(.*\\)");const std::regex range_pattern(- "[[0-9]*[a-z A-Z]+[0-9]*:\\[([+-]?([0-9]*[.])?[0-9]*)\\,\\s*([+-]?([0-9]*[.])?[0-9]*)\\]");+ "[[:print:]]+:\\[([+-]?([[:digit:]]*[.])?[[:digit:]]*)\\,\\s*([+-]?([[:digit:]]*[.])?[[:digit:]]*)\\]");const std::string _alpha = "_alpha";if((facet_field.find(":") != std::string::npos)diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cppindex 3882ffaa..f9f41515 100644--- a/test/collection_faceting_test.cpp+++ b/test/collection_faceting_test.cpp@@ -1363,6 +1363,31 @@ TEST_F(CollectionFacetingTest, FacetParseTest){coll1->parse_facet(facet_range, range_facets_with_sort_as_field);ASSERT_EQ(1, range_facets_with_sort_as_field.size());++ //range facet label with special chars+ std::vector<std::string> range_facet_special_chars{+ "score(%0 - %19:[0, 20], %20 - %59:[20, 60], %60+:[60, ])",+ "range($$$:[0, 20])"+ };++ std::vector<facet> facet_speical_chars;+ for(const std::string& facet_field: range_facet_special_chars) {+ auto res = coll1->parse_facet(facet_field, facet_speical_chars);++ if(!res.error().empty()) {+ LOG(ERROR) << res.error();+ FAIL();+ }+ }++ //should not allow to pass only space chars+ facet_speical_chars.clear();+ auto only_space_char("review( :[0, 20])");++ auto res = coll1->parse_facet(only_space_char, facet_speical_chars);+ ASSERT_FALSE(res.error().empty());+ ASSERT_EQ(400, res.code());+ ASSERT_EQ("Facet range value is not valid.", res.error());}TEST_F(CollectionFacetingTest, RangeFacetTest) {diff --git a/test/collection_optimized_faceting_test.cpp b/test/collection_optimized_faceting_test.cppindex c5643e67..2dad906a 100644--- a/test/collection_optimized_faceting_test.cpp+++ b/test/collection_optimized_faceting_test.cpp@@ -1061,6 +1061,31 @@ TEST_F(CollectionOptimizedFacetingTest, FacetParseTest){coll1->parse_facet(facet_range, range_facets_with_sort_as_field);ASSERT_EQ(1, range_facets_with_sort_as_field.size());++ //range facet label with special chars+ std::vector<std::string> range_facet_special_chars{+ "score(%0 - %19:[0, 20], %20 - %59:[20, 60], %60+:[60, ])",+ "range($$$:[0, 20])"+ };++ std::vector<facet> facet_speical_chars;+ for(const std::string& facet_field: range_facet_special_chars) {+ auto res = coll1->parse_facet(facet_field, facet_speical_chars);++ if(!res.error().empty()) {+ LOG(ERROR) << res.error();+ FAIL();+ }+ }++ //should not allow to pass only space chars+ facet_speical_chars.clear();+ auto only_space_char("range( :[0, 20])");++ auto res = coll1->parse_facet(only_space_char, facet_speical_chars);+ ASSERT_FALSE(res.error().empty());+ ASSERT_EQ(400, res.code());+ ASSERT_EQ("Facet range value is not valid.", res.error());}TEST_F(CollectionOptimizedFacetingTest, RangeFacetTest) {