mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 14:12:27 +08:00
Merge pull request #1098 from happy-san/v0.25-join
Limit `filter_by` on number of operations.
This commit is contained in:
commit
71fb17d3be
@ -489,16 +489,16 @@ Option<bool> filter::parse_filter_query(const std::string& filter_query,
|
||||
return tokenize_op;
|
||||
}
|
||||
|
||||
if (tokens.size() > 100) {
|
||||
return Option<bool>(400, "Filter expression is not valid.");
|
||||
}
|
||||
|
||||
std::queue<std::string> postfix;
|
||||
Option<bool> toPostfix_op = toPostfix(tokens, postfix);
|
||||
if (!toPostfix_op.ok()) {
|
||||
return toPostfix_op;
|
||||
}
|
||||
|
||||
if (postfix.size() > 100) {
|
||||
return Option<bool>(400, "`filter_by` has too many operations.");
|
||||
}
|
||||
|
||||
Option<bool> toParseTree_op = toParseTree(postfix,
|
||||
root,
|
||||
search_schema,
|
||||
|
@ -2627,5 +2627,27 @@ TEST_F(CollectionFilteringTest, ComplexFilterQuery) {
|
||||
ASSERT_STREQ(id.c_str(), result_id.c_str());
|
||||
}
|
||||
|
||||
std::string extreme_filter = "(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))) ||"
|
||||
"(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))) ||"
|
||||
"(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))) ||"
|
||||
"(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))) ||"
|
||||
"(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))) ||"
|
||||
"(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))) ||"
|
||||
"(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))) ||"
|
||||
"(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))) ||"
|
||||
"(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))) ||"
|
||||
"(years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5)))";
|
||||
|
||||
auto search_op = coll->search("Jeremy", {"name"}, extreme_filter,
|
||||
{}, sort_fields_desc, {0}, 10, 1, FREQUENCY, {false});
|
||||
ASSERT_TRUE(search_op.ok());
|
||||
ASSERT_EQ(1, search_op.get()["hits"].size());
|
||||
|
||||
extreme_filter += "|| (years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5)))";
|
||||
search_op = coll->search("Jeremy", {"name"}, extreme_filter,
|
||||
{}, sort_fields_desc, {0}, 10, 1, FREQUENCY, {false});
|
||||
ASSERT_FALSE(search_op.ok());
|
||||
ASSERT_EQ("`filter_by` has too many operations.", search_op.error());
|
||||
|
||||
collectionManager.drop_collection("ComplexFilterQueryCollection");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user