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

Accept empty array as filter value.

Harpreet Sangarc52bd6c55e25
diff --git a/src/filter.cpp b/src/filter.cpp
index 95b512ba..757bb4b7 100644
--- a/src/filter.cpp
+++ b/src/filter.cpp
@@ -639,10 +639,6 @@ Option<bool> toFilter(const std::string expression,
std::vector<std::string> filter_values;
StringUtils::split_to_values(
raw_value.substr(filter_value_index + 1, raw_value.size() - filter_value_index - 2), filter_values);
- if (filter_values.empty()) {
- return Option<bool>(400, "Error with filter field `" + _field.name +
- "`: Filter value array cannot be empty.");
- }
if(_field.stem) {
auto stemmer = _field.get_stemmer();
for (std::string& filter_value: filter_values) {
diff --git a/test/collection_filtering_test.cpp b/test/collection_filtering_test.cpp
index 8e236f4f..63fac08c 100644
--- a/test/collection_filtering_test.cpp
+++ b/test/collection_filtering_test.cpp
@@ -1593,6 +1593,9 @@ TEST_F(CollectionFilteringTest, NegationOperatorBasics) {
results = coll1->search("*", {"artist"}, "artist:![Swift, Jackson]", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10).get();
ASSERT_EQ(0, results["found"]);
+ results = coll1->search("*", {"artist"}, "artist:!=[]", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10).get();
+ ASSERT_EQ(4, results["found"]);
+
// empty value (bad filtering)
auto res_op = coll1->search("*", {"artist"}, "artist:!=", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10);
ASSERT_FALSE(res_op.ok());
@@ -1610,10 +1613,6 @@ TEST_F(CollectionFilteringTest, NegationOperatorBasics) {
ASSERT_FALSE(res_op.ok());
ASSERT_EQ("Error with filter field `artist`: Filter value cannot be empty.", res_op.error());
- res_op = coll1->search("*", {"artist"}, "artist:!=[]", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10);
- ASSERT_FALSE(res_op.ok());
- ASSERT_EQ("Error with filter field `artist`: Filter value array cannot be empty.", res_op.error());
-
collectionManager.drop_collection("coll1");
}
@@ -1677,6 +1676,11 @@ TEST_F(CollectionFilteringTest, FilterStringsWithComma) {
ASSERT_EQ(1, results["found"].get<size_t>());
ASSERT_STREQ("0", results["hits"][0]["document"]["id"].get<std::string>().c_str());
+ results = coll1->search("*", {"place"}, "place: []", {}, {}, {0}, 10, 1,
+ FREQUENCY, {true}, 10).get();
+
+ ASSERT_EQ(0, results["found"].get<size_t>());
+
collectionManager.drop_collection("coll1");
}