mirror of
https://github.com/typesense/typesense.git
synced 2025-05-20 21:52:23 +08:00
Empty filter value fix. (#1571)
* Empty filter value fix. * Add test case.
This commit is contained in:
parent
0013c50ffd
commit
ec186c032e
@ -629,6 +629,11 @@ 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.");
|
||||
}
|
||||
|
||||
filter_exp = {field_name, filter_values, {str_comparator}};
|
||||
} else {
|
||||
filter_exp = {field_name, {raw_value.substr(filter_value_index)}, {str_comparator}};
|
||||
|
@ -1170,12 +1170,19 @@ void filter_result_iterator_t::init() {
|
||||
raw_posting_lists.push_back(leaf->values);
|
||||
}
|
||||
|
||||
if (raw_posting_lists.size() != str_tokens.size()) {
|
||||
if (str_tokens.empty()) {
|
||||
status = Option<bool>(400, "Error with filter field `" + f.name + "`: Filter value cannot be empty.");
|
||||
validity = invalid;
|
||||
return;
|
||||
} else if (raw_posting_lists.size() != str_tokens.size()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<posting_list_t*> plists;
|
||||
posting_t::to_expanded_plists(raw_posting_lists, plists, expanded_plists);
|
||||
if (plists.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
posting_lists.push_back(plists);
|
||||
posting_list_iterators.emplace_back(std::vector<posting_list_t::iterator_t>());
|
||||
|
@ -82,6 +82,10 @@ TEST_F(CollectionFilteringTest, FilterOnTextFields) {
|
||||
results = coll_array_fields->search("Jeremy", query_fields, "tags : PLATINUM", facets, sort_fields, {0}, 10, 1, FREQUENCY, {false}).get();
|
||||
ASSERT_EQ(1, results["hits"].size());
|
||||
|
||||
// no documents contain "white"
|
||||
results = coll_array_fields->search("Jeremy", query_fields, "tags : WHITE", facets, sort_fields, {0}, 10, 1, FREQUENCY, {false}).get();
|
||||
ASSERT_EQ(0, results["hits"].size());
|
||||
|
||||
// no documents contain both "white" and "platinum", so
|
||||
results = coll_array_fields->search("Jeremy", query_fields, "tags : WHITE PLATINUM", facets, sort_fields, {0}, 10, 1, FREQUENCY, {false}).get();
|
||||
ASSERT_EQ(0, results["hits"].size());
|
||||
@ -1488,6 +1492,18 @@ 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 cannot be empty.", res_op.error());
|
||||
|
||||
res_op = coll1->search("*", {"artist"}, "artist:!=[`foo`, ``]", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10);
|
||||
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");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user