mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 14:12:27 +08:00
Fix query_by crash.
This commit is contained in:
parent
09a8f5d537
commit
0726c17804
@ -1806,7 +1806,8 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
|
||||
// `id` field needs to be handled separately, we will not handle for now
|
||||
std::string error = "Cannot use `id` as a query by field.";
|
||||
return Option<nlohmann::json>(400, error);
|
||||
} else if (field_name[0] == '$') {
|
||||
} else if (field_name[0] == '$' && field_name.find('(') != std::string::npos &&
|
||||
field_name.find(')') != std::string::npos) {
|
||||
return Option<nlohmann::json>(400, "Query by reference is not yet supported.");
|
||||
}
|
||||
|
||||
@ -1817,6 +1818,9 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
|
||||
}
|
||||
|
||||
for(const auto& expanded_search_field: expanded_search_fields) {
|
||||
if (search_schema.count(expanded_search_field) == 0) {
|
||||
return Option<nlohmann::json>(400, "Could not find `" + expanded_search_field + "` field in the schema.");
|
||||
}
|
||||
auto search_field = search_schema.at(expanded_search_field);
|
||||
|
||||
if(search_field.num_dim > 0) {
|
||||
|
@ -4980,4 +4980,13 @@ TEST_F(CollectionJoinTest, QueryByReference) {
|
||||
auto search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
|
||||
ASSERT_FALSE(search_op.ok());
|
||||
ASSERT_EQ("Query by reference is not yet supported.", search_op.error());
|
||||
|
||||
req_params = {
|
||||
{"collection", "Products"},
|
||||
{"q", "*"},
|
||||
{"query_by", "$Customers(customer_name"}
|
||||
};
|
||||
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
|
||||
ASSERT_FALSE(search_op.ok());
|
||||
ASSERT_EQ("Could not find `$Customers(customer_name` field in the schema.", search_op.error());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user