mirror of
https://github.com/typesense/typesense.git
synced 2025-05-17 04:02:36 +08:00
Fix docs_updated_count
getting garbage value.
Fix `StringUtils::split_include_fields` not trimming last value.
This commit is contained in:
parent
a7d549d0ae
commit
e277415ccb
@ -419,7 +419,7 @@ Option<nlohmann::json> Collection::update_matching_filter(const std::string& fil
|
||||
}
|
||||
|
||||
const auto& dirty_values = parse_dirty_values_option(req_dirty_values);
|
||||
size_t docs_updated_count;
|
||||
size_t docs_updated_count = 0;
|
||||
nlohmann::json update_document, dummy;
|
||||
|
||||
try {
|
||||
|
@ -464,7 +464,11 @@ Option<bool> StringUtils::split_include_fields(const std::string& include_fields
|
||||
|
||||
if (range_pos == std::string::npos && comma_pos == std::string::npos) {
|
||||
if (start < size - 1) {
|
||||
tokens.push_back(include_fields.substr(start, size - start));
|
||||
include_field = include_fields.substr(start, size - start);
|
||||
include_field = trim(include_field);
|
||||
if (!include_field.empty()) {
|
||||
tokens.push_back(include_field);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else if (range_pos < comma_pos) {
|
||||
|
@ -391,7 +391,32 @@ TEST(StringUtilsTest, TokenizeFilterQuery) {
|
||||
tokenList = {"(", "(", "age:<5", "||", "age:>10", ")", "&&", "location:(48.906,2.343,5mi)", ")", "||", "tags:AT&T"};
|
||||
tokenizeTestHelper(filter_query, tokenList);
|
||||
|
||||
filter_query = "((age: <5 || age: >10) && category:= [shoes]) && $Customers(customer_id:=customer_a && (product_price:>100 && product_price:<200))";
|
||||
tokenList = {"(", "(", "age: <5", "||", "age: >10", ")", "&&", "category:= [shoes]", ")", "&&", "$Customers(customer_id:=customer_a && (product_price:>100 && product_price:<200))"};
|
||||
filter_query = "((age: <5 || age: >10) && category:= [shoes]) &&"
|
||||
" $Customers(customer_id:=customer_a && (product_price:>100 && product_price:<200))";
|
||||
tokenList = {"(", "(", "age: <5", "||", "age: >10", ")", "&&", "category:= [shoes]", ")", "&&",
|
||||
"$Customers(customer_id:=customer_a && (product_price:>100 && product_price:<200))"};
|
||||
tokenizeTestHelper(filter_query, tokenList);
|
||||
}
|
||||
|
||||
void splitIncludeTestHelper(const std::string& include_fields, const std::vector<std::string>& expected) {
|
||||
std::vector<std::string> output;
|
||||
auto tokenize_op = StringUtils::split_include_fields(include_fields, output);
|
||||
ASSERT_TRUE(tokenize_op.ok());
|
||||
ASSERT_EQ(expected.size(), output.size());
|
||||
for (auto i = 0; i < output.size(); i++) {
|
||||
ASSERT_EQ(expected[i], output[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(StringUtilsTest, SplitIncludeFields) {
|
||||
std::string include_fields;
|
||||
std::vector<std::string> tokens;
|
||||
|
||||
include_fields = "id, title, count";
|
||||
tokens = {"id", "title", "count"};
|
||||
splitIncludeTestHelper(include_fields, tokens);
|
||||
|
||||
include_fields = "id, $Collection(title, pref*), count";
|
||||
tokens = {"id", "$Collection(title, pref*)", "count"};
|
||||
splitIncludeTestHelper(include_fields, tokens);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user