mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 12:42:50 +08:00
Fix single character full field value highlight.
This commit is contained in:
parent
672c895805
commit
e42f78a695
@ -1704,7 +1704,9 @@ void Collection::highlight_result(const field &search_field,
|
||||
if(offset_it != token_offsets.end()) {
|
||||
if (i == offset_it->first) {
|
||||
value_stream << highlight_start_tag;
|
||||
} else if (i == offset_it->second) {
|
||||
}
|
||||
|
||||
if (i == offset_it->second) {
|
||||
value_stream << text[i];
|
||||
value_stream << highlight_end_tag;
|
||||
offset_it++;
|
||||
|
@ -910,8 +910,6 @@ void Index::search_candidates(const uint8_t & field_id,
|
||||
auto product = []( long long a, token_candidates & b ) { return a*b.candidates.size(); };
|
||||
long long int N = std::accumulate(token_candidates_vec.begin(), token_candidates_vec.end(), 1LL, product);
|
||||
|
||||
size_t last_cost = 0;
|
||||
|
||||
for(long long n=0; n<N && n<combination_limit; ++n) {
|
||||
// every element in `query_suggestion` contains a token and its associated hits
|
||||
std::vector<art_leaf*> query_suggestion(token_candidates_vec.size());
|
||||
@ -924,12 +922,6 @@ void Index::search_candidates(const uint8_t & field_id,
|
||||
query_suggestion, token_bits);
|
||||
|
||||
//LOG(INFO) << "field_num_results: " << field_num_results << ", typo_tokens_threshold: " << typo_tokens_threshold;
|
||||
if(total_cost != last_cost && field_num_results >= typo_tokens_threshold) {
|
||||
//break;
|
||||
}
|
||||
|
||||
last_cost = total_cost;
|
||||
|
||||
/*LOG(INFO) << "n: " << n;
|
||||
for(size_t i=0; i < actual_query_suggestion.size(); i++) {
|
||||
LOG(INFO) << "i: " << i << " - " << actual_query_suggestion[i]->key << ", ids: "
|
||||
|
@ -525,3 +525,34 @@ TEST_F(CollectionSpecificTest, DeleteOverridesAndSynonymsOnDiskDuringCollDrop) {
|
||||
store->scan_fill(Collection::COLLECTION_SYNONYM_PREFIX, stored_values);
|
||||
ASSERT_TRUE(stored_values.empty());
|
||||
}
|
||||
|
||||
TEST_F(CollectionSpecificTest, SingleCharMatchFullFieldHighlight) {
|
||||
std::vector<field> fields = {field("title", field_types::STRING, false),
|
||||
field("points", field_types::INT32, false),};
|
||||
|
||||
Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get();
|
||||
|
||||
nlohmann::json doc1;
|
||||
doc1["id"] = "0";
|
||||
doc1["title"] = "Which of the following is a probable sign of infection?";
|
||||
doc1["points"] = 100;
|
||||
|
||||
ASSERT_TRUE(coll1->add(doc1.dump()).ok());
|
||||
|
||||
auto results = coll1->search("a 3-month", {"title"}, "", {}, {}, {2}, 10,
|
||||
1, FREQUENCY, {false}, 1,
|
||||
spp::sparse_hash_set<std::string>(),
|
||||
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
|
||||
"title", 1).get();
|
||||
|
||||
ASSERT_EQ(1, results["hits"].size());
|
||||
ASSERT_EQ("0", results["hits"][0]["document"]["id"].get<std::string>());
|
||||
|
||||
ASSERT_EQ("Which of the following is <mark>a</mark> probable sign of infection?",
|
||||
results["hits"][0]["highlights"][0]["snippet"].get<std::string>());
|
||||
|
||||
ASSERT_EQ("Which of the following is <mark>a</mark> probable sign of infection?",
|
||||
results["hits"][0]["highlights"][0]["value"].get<std::string>());
|
||||
|
||||
collectionManager.drop_collection("coll1");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user