Support highlighting in dynamic filter query.

This commit is contained in:
Kishore Nallan 2021-10-13 12:37:57 +05:30
parent 0591fd508c
commit c2eb31d33b
2 changed files with 9 additions and 4 deletions

View File

@ -1437,16 +1437,18 @@ void Collection::highlight_result(const field &search_field,
const std::string& highlight_end_tag,
highlight_t & highlight) const {
if(searched_queries.size() <= field_order_kv->query_index) {
return ;
}
std::vector<art_leaf*> query_suggestion;
std::set<std::string> query_suggestion_tokens;
size_t qindex = 0;
do {
if(searched_queries.size() <= field_order_kv->query_index) {
// in filter based overrides with matched tokens removal, we could have no queries but still might
// want to highlight fields from actual query tokens
break;
}
auto searched_query =
(field_order_kv->query_indices == nullptr) ? searched_queries[field_order_kv->query_index] :
searched_queries[field_order_kv->query_indices[qindex + 1]];

View File

@ -886,6 +886,9 @@ TEST_F(CollectionOverrideTest, DynamicFilteringExactMatchBasics) {
ASSERT_EQ("1", results["hits"][0]["document"]["id"].get<std::string>());
ASSERT_EQ("0", results["hits"][1]["document"]["id"].get<std::string>());
ASSERT_EQ("<mark>shoes</mark>", results["hits"][0]["highlights"][0]["snippet"].get<std::string>());
ASSERT_EQ("<mark>shoes</mark>", results["hits"][1]["highlights"][0]["snippet"].get<std::string>());
// should not apply filter for non-exact case
results = coll1->search("running shoes", {"name", "category", "brand"}, "",
{}, sort_fields, {2, 2, 2}, 10).get();