mirror of
https://github.com/typesense/typesense.git
synced 2025-05-20 05:32:30 +08:00
Use != as negation operation to cope with numbers also.
This commit is contained in:
parent
9015575ac8
commit
a66123f961
@ -2232,7 +2232,7 @@ Option<bool> Collection::parse_filter_query(const std::string& simple_filter_que
|
||||
// string filter should be evaluated in strict "equals" mode
|
||||
str_comparator = EQUALS;
|
||||
while(raw_value[++filter_value_index] == ' ');
|
||||
} else if(raw_value[0] == '-') {
|
||||
} else if(raw_value.size() >= 2 && raw_value[0] == '!' && raw_value[1] == '=') {
|
||||
if(!_field.facet) {
|
||||
// EXCLUDE filtering on string is possible only on facet fields
|
||||
return Option<bool>(400, "To perform exclude filtering, filter field `" +
|
||||
|
@ -1323,7 +1323,7 @@ TEST_F(CollectionFilteringTest, NegationOperatorBasics) {
|
||||
ASSERT_TRUE(coll1->add(doc.dump()).ok());
|
||||
}
|
||||
|
||||
auto results = coll1->search("*", {"artist"}, "artist:- Michael Jackson", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10).get();
|
||||
auto results = coll1->search("*", {"artist"}, "artist:!= Michael Jackson", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10).get();
|
||||
|
||||
ASSERT_EQ(3, results["found"].get<size_t>());
|
||||
|
||||
@ -1331,14 +1331,14 @@ TEST_F(CollectionFilteringTest, NegationOperatorBasics) {
|
||||
ASSERT_STREQ("2", results["hits"][1]["document"]["id"].get<std::string>().c_str());
|
||||
ASSERT_STREQ("0", results["hits"][2]["document"]["id"].get<std::string>().c_str());
|
||||
|
||||
results = coll1->search("*", {"artist"}, "artist:- Michael Jackson && points: >0", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10).get();
|
||||
results = coll1->search("*", {"artist"}, "artist:!= Michael Jackson && points: >0", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10).get();
|
||||
ASSERT_EQ(2, results["found"].get<size_t>());
|
||||
ASSERT_STREQ("3", results["hits"][0]["document"]["id"].get<std::string>().c_str());
|
||||
ASSERT_STREQ("2", results["hits"][1]["document"]["id"].get<std::string>().c_str());
|
||||
|
||||
// negation operation on multiple values
|
||||
|
||||
results = coll1->search("*", {"artist"}, "artist:- [Michael Jackson, Taylor Swift]", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10).get();
|
||||
results = coll1->search("*", {"artist"}, "artist:!= [Michael Jackson, Taylor Swift]", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 10).get();
|
||||
ASSERT_EQ(1, results["found"].get<size_t>());
|
||||
ASSERT_STREQ("3", results["hits"][0]["document"]["id"].get<std::string>().c_str());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user