mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-10 15:08:56 +01:00
Highlights result with longest match
This commit is contained in:
parent
1b7a6687c8
commit
16e075983d
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1141,6 +1141,7 @@ dependencies = [
|
||||
"serde_qs",
|
||||
"sha2",
|
||||
"siphasher",
|
||||
"slice-group-by",
|
||||
"structopt",
|
||||
"sysinfo",
|
||||
"tempdir",
|
||||
|
@ -42,6 +42,7 @@ tide = "0.6.0"
|
||||
ureq = { version = "0.12.0", features = ["tls"], default-features = false }
|
||||
walkdir = "2.3.1"
|
||||
whoami = "0.8.1"
|
||||
slice-group-by = "0.2.6"
|
||||
|
||||
[dev-dependencies]
|
||||
http-service = "0.4.0"
|
||||
|
@ -17,6 +17,7 @@ use meilisearch_tokenizer::is_cjk;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use siphasher::sip::SipHasher;
|
||||
use slice_group_by::GroupBy;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
@ -526,7 +527,12 @@ fn calculate_highlights(
|
||||
let value: Vec<_> = value.chars().collect();
|
||||
let mut highlighted_value = String::new();
|
||||
let mut index = 0;
|
||||
for m in matches {
|
||||
|
||||
let longest_matches = matches
|
||||
.linear_group_by_key(|m| m.start)
|
||||
.map(|group| group.last().unwrap());
|
||||
|
||||
for m in longest_matches {
|
||||
if m.start >= index {
|
||||
let before = value.get(index..m.start);
|
||||
let highlighted = value.get(m.start..(m.start + m.length));
|
||||
|
Loading…
Reference in New Issue
Block a user