mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
fix highlight shifting bug
This commit is contained in:
parent
808be4678a
commit
748a8240dd
@ -199,8 +199,8 @@ fn index_token(
|
|||||||
|
|
||||||
fn token_to_docindex(id: DocumentId, indexed_pos: IndexedPos, token: &Token, word_index: usize) -> Option<DocIndex> {
|
fn token_to_docindex(id: DocumentId, indexed_pos: IndexedPos, token: &Token, word_index: usize) -> Option<DocIndex> {
|
||||||
let word_index = u16::try_from(word_index).ok()?;
|
let word_index = u16::try_from(word_index).ok()?;
|
||||||
let char_index = u16::try_from(token.char_index).ok()?;
|
let char_index = u16::try_from(token.byte_start).ok()?;
|
||||||
let char_length = u16::try_from(token.word.chars().count()).ok()?;
|
let char_length = u16::try_from(token.word.len()).ok()?;
|
||||||
|
|
||||||
let docindex = DocIndex {
|
let docindex = DocIndex {
|
||||||
document_id: id,
|
document_id: id,
|
||||||
|
@ -479,7 +479,7 @@ fn calculate_highlights(
|
|||||||
for (attribute, matches) in matches.iter() {
|
for (attribute, matches) in matches.iter() {
|
||||||
if attributes_to_highlight.contains(attribute) {
|
if attributes_to_highlight.contains(attribute) {
|
||||||
if let Some(Value::String(value)) = document.get(attribute) {
|
if let Some(Value::String(value)) = document.get(attribute) {
|
||||||
let value: Vec<_> = value.chars().collect();
|
let value = value.clone();
|
||||||
let mut highlighted_value = String::new();
|
let mut highlighted_value = String::new();
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
|
||||||
@ -492,16 +492,16 @@ fn calculate_highlights(
|
|||||||
let before = value.get(index..m.start);
|
let before = value.get(index..m.start);
|
||||||
let highlighted = value.get(m.start..(m.start + m.length));
|
let highlighted = value.get(m.start..(m.start + m.length));
|
||||||
if let (Some(before), Some(highlighted)) = (before, highlighted) {
|
if let (Some(before), Some(highlighted)) = (before, highlighted) {
|
||||||
highlighted_value.extend(before);
|
highlighted_value.push_str(before);
|
||||||
highlighted_value.push_str("<em>");
|
highlighted_value.push_str("<em>");
|
||||||
highlighted_value.extend(highlighted);
|
highlighted_value.push_str(highlighted);
|
||||||
highlighted_value.push_str("</em>");
|
highlighted_value.push_str("</em>");
|
||||||
index = m.start + m.length;
|
index = m.start + m.length;
|
||||||
} else {
|
} else {
|
||||||
error!("value: {:?}; index: {:?}, match: {:?}", value, index, m);
|
error!("value: {:?}; index: {:?}, match: {:?}", value, index, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
highlighted_value.extend(value[index..].iter());
|
highlighted_value.push_str(&value[index..]);
|
||||||
highlight_result.insert(attribute.to_string(), Value::String(highlighted_value));
|
highlight_result.insert(attribute.to_string(), Value::String(highlighted_value));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user