Merge pull request #1098 from happy-san/v0.25-join

Limit `filter_by` on number of operations.
This commit is contained in:
Kishore Nallan 2023-07-11 15:06:58 +05:30 committed by GitHub
commit 71fb17d3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View File

@ -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,

View File

@ -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");
}