mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 14:12:27 +08:00
Support join on bases of query match with $foo(id: *)
.
This commit is contained in:
parent
b69e2a2687
commit
13b7d8ed71
@ -418,7 +418,11 @@ Option<bool> toFilter(const std::string expression,
|
||||
filter_exp = {field_name, {}, {}};
|
||||
NUM_COMPARATOR id_comparator = EQUALS;
|
||||
size_t filter_value_index = 0;
|
||||
if (raw_value[0] == '=') {
|
||||
if (raw_value == "*") { // Match all.
|
||||
// NOT_EQUALS comparator with no id match will get all the ids.
|
||||
id_comparator = NOT_EQUALS;
|
||||
filter_exp.apply_not_equals = true;
|
||||
} else if (raw_value[0] == '=') {
|
||||
id_comparator = EQUALS;
|
||||
while (++filter_value_index < raw_value.size() && raw_value[filter_value_index] == ' ');
|
||||
} else if (raw_value.size() >= 2 && raw_value[0] == '!' && raw_value[1] == '=') {
|
||||
|
@ -659,7 +659,8 @@ void filter_result_iterator_t::init() {
|
||||
values.push_back(std::to_string(result.docs[i]));
|
||||
}
|
||||
|
||||
filter filter_exp = {get_reference_field_op.get(), std::move(values), {EQUALS}};
|
||||
filter filter_exp = {get_reference_field_op.get(), std::move(values),
|
||||
std::vector<NUM_COMPARATOR>(result.count, EQUALS)};
|
||||
|
||||
auto filter_tree_root = new filter_node_t(filter_exp);
|
||||
std::unique_ptr<filter_node_t> filter_tree_root_guard(filter_tree_root);
|
||||
|
@ -1327,6 +1327,13 @@ TEST_F(CollectionFilteringTest, FilteringViaDocumentIds) {
|
||||
|
||||
ASSERT_EQ(0, results["found"].get<size_t>());
|
||||
|
||||
// match all IDs
|
||||
results = coll1->search("*",
|
||||
{}, "id: *",
|
||||
{}, sort_fields, {0}, 10, 1, FREQUENCY, {true}).get();
|
||||
|
||||
ASSERT_EQ(4, results["found"].get<size_t>());
|
||||
|
||||
collectionManager.drop_collection("coll1");
|
||||
}
|
||||
|
||||
|
@ -482,6 +482,21 @@ TEST_F(CollectionJoinTest, FilterByReference_SingleMatch) {
|
||||
ASSERT_EQ(1, res_obj["hits"].size());
|
||||
ASSERT_EQ("soap", result["hits"][0]["document"]["product_name"].get<std::string>());
|
||||
|
||||
req_params = {
|
||||
{"collection", "Customers"},
|
||||
{"q", "Dan"},
|
||||
{"query_by", "customer_name"},
|
||||
{"filter_by", "$Products(id:*) && product_price:<100"},
|
||||
};
|
||||
|
||||
search_op_bool = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
|
||||
ASSERT_TRUE(search_op_bool.ok());
|
||||
|
||||
res_obj = nlohmann::json::parse(json_res);
|
||||
ASSERT_EQ(1, res_obj["found"].get<size_t>());
|
||||
ASSERT_EQ(1, res_obj["hits"].size());
|
||||
ASSERT_EQ("soap", result["hits"][0]["document"]["product_name"].get<std::string>());
|
||||
|
||||
collectionManager.drop_collection("Customers");
|
||||
collectionManager.drop_collection("Products");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user