Allow highlighting to be skipped via non-indexed field.

This commit is contained in:
Kishore Nallan 2021-10-30 11:54:19 +05:30
parent 4844f19c50
commit 3eed0d509e
2 changed files with 16 additions and 0 deletions

View File

@ -1070,6 +1070,10 @@ Option<nlohmann::json> Collection::search(const std::string & raw_query, const s
const std::string& field_name = fields_highlighted_vec[i];
const std::vector<std::string>& q_tokens = field_query_tokens[fields_highlighted_indices[i]].q_include_tokens;
if(search_schema.count(field_name) == 0) {
continue;
}
field search_field = search_schema.at(field_name);
if(query != "*" && (search_field.type == field_types::STRING ||
search_field.type == field_types::STRING_ARRAY)) {
@ -1369,6 +1373,7 @@ bool Collection::facet_value_to_string(const facet &a_facet, const facet_count_t
const nlohmann::json &document, std::string &value) const {
if(document.count(a_facet.field_name) == 0) {
// check for field exists
if(search_schema.at(a_facet.field_name).optional) {
return false;
}

View File

@ -142,6 +142,17 @@ TEST_F(CollectionSpecificTest, ExplicitHighlightFieldsConfig) {
ASSERT_EQ(1, results["hits"].size());
ASSERT_EQ(0, results["hits"][0]["highlights"].size());
// highlight field that does not exist
results = coll1->search("brown fox pernell", {"title"}, "", {}, {}, {2}, 10,
1, FREQUENCY, {false}, 1, spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "", 1, {}, {}, {}, 0,
"<mark>", "</mark>", {1}, 10000, true, false, true, "not-found").get();
ASSERT_EQ(1, results["found"].get<size_t>());
ASSERT_EQ(1, results["hits"].size());
ASSERT_EQ(0, results["hits"][0]["highlights"].size());
collectionManager.drop_collection("coll1");
}