mirror of
https://github.com/typesense/typesense.git
synced 2025-05-17 04:02:36 +08:00
Change structure of hightlight in response to allow sending the matched array index.
This commit is contained in:
parent
d4d1a9e3bd
commit
33552ca627
@ -625,7 +625,12 @@ Option<nlohmann::json> Collection::search(std::string query, const std::vector<s
|
||||
}
|
||||
|
||||
wrapper_doc["highlight"] = nlohmann::json::object();
|
||||
wrapper_doc["highlight"][field_name] = snippet_stream.str();
|
||||
wrapper_doc["highlight"][field_name] = nlohmann::json::object();
|
||||
wrapper_doc["highlight"][field_name]["value"] = snippet_stream.str();
|
||||
|
||||
if(search_field.type == field_types::STRING_ARRAY) {
|
||||
wrapper_doc["highlight"][field_name]["index"] = matched_array_index;
|
||||
}
|
||||
|
||||
for (auto it = leaf_to_indices.begin(); it != leaf_to_indices.end(); it++) {
|
||||
delete [] it->second;
|
||||
|
@ -534,7 +534,9 @@ TEST_F(CollectionTest, ArrayStringFieldHighlight) {
|
||||
ASSERT_STREQ(id.c_str(), result_id.c_str());
|
||||
}
|
||||
|
||||
ASSERT_STREQ(results["hits"][0]["highlight"]["tags"].get<std::string>().c_str(), "<mark>truth</mark> <mark>about</mark>");
|
||||
ASSERT_STREQ(results["hits"][0]["highlight"]["tags"]["value"].get<std::string>().c_str(),
|
||||
"<mark>truth</mark> <mark>about</mark>");
|
||||
ASSERT_EQ(results["hits"][0]["highlight"]["tags"]["index"].get<size_t>(), 2);
|
||||
|
||||
results = coll_array_text->search("forever truth", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,
|
||||
false, 0).get();
|
||||
@ -549,7 +551,9 @@ TEST_F(CollectionTest, ArrayStringFieldHighlight) {
|
||||
ASSERT_STREQ(id.c_str(), result_id.c_str());
|
||||
}
|
||||
|
||||
ASSERT_STREQ(results["hits"][0]["highlight"]["tags"].get<std::string>().c_str(), "the <mark>truth</mark>");
|
||||
ASSERT_STREQ(results["hits"][0]["highlight"]["tags"]["value"].get<std::string>().c_str(),
|
||||
"the <mark>truth</mark>");
|
||||
ASSERT_EQ(results["hits"][0]["highlight"]["tags"]["index"].get<size_t>(), 0);
|
||||
|
||||
results = coll_array_text->search("truth", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,
|
||||
false, 0).get();
|
||||
|
Loading…
x
Reference in New Issue
Block a user