mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-18 08:48:32 +08:00
Search; return formated section only if it's necessary
This commit is contained in:
parent
bf80729e17
commit
04d34cb8aa
@ -243,7 +243,14 @@ impl<'a> SearchBuilder<'a> {
|
|||||||
.map_err(|e| Error::RetrieveDocument(doc.id.0, e.to_string()))?
|
.map_err(|e| Error::RetrieveDocument(doc.id.0, e.to_string()))?
|
||||||
.ok_or(Error::DocumentNotFound(doc.id.0))?;
|
.ok_or(Error::DocumentNotFound(doc.id.0))?;
|
||||||
|
|
||||||
let mut formatted = document.clone();
|
let has_attributes_to_highlight = self.attributes_to_highlight.is_some();
|
||||||
|
let has_attributes_to_crop = self.attributes_to_crop.is_some();
|
||||||
|
|
||||||
|
let mut formatted = if has_attributes_to_highlight || has_attributes_to_crop {
|
||||||
|
document.clone()
|
||||||
|
} else {
|
||||||
|
IndexMap::new()
|
||||||
|
};
|
||||||
let mut matches = doc.highlights.clone();
|
let mut matches = doc.highlights.clone();
|
||||||
|
|
||||||
// Crops fields if needed
|
// Crops fields if needed
|
||||||
@ -494,7 +501,7 @@ fn calculate_highlights(
|
|||||||
matches: &MatchesInfos,
|
matches: &MatchesInfos,
|
||||||
attributes_to_highlight: &HashSet<String>,
|
attributes_to_highlight: &HashSet<String>,
|
||||||
) -> IndexMap<String, Value> {
|
) -> IndexMap<String, Value> {
|
||||||
let mut highlight_result = IndexMap::new();
|
let mut highlight_result = document.clone();
|
||||||
|
|
||||||
for (attribute, matches) in matches.iter() {
|
for (attribute, matches) in matches.iter() {
|
||||||
if attributes_to_highlight.contains(attribute) {
|
if attributes_to_highlight.contains(attribute) {
|
||||||
|
Loading…
Reference in New Issue
Block a user