mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 20:52:50 +08:00
Accept empty array as filter value.
This commit is contained in:
parent
673d36f2b0
commit
c52bd6c55e
@ -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) {
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user