From 3a2e7d3c3bb056c83911ce26f3e04d21555d7158 Mon Sep 17 00:00:00 2001 From: marin postma Date: Sun, 20 Jun 2021 16:59:31 +0200 Subject: [PATCH 1/2] optimize cropping --- meilisearch-http/src/index/search.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/meilisearch-http/src/index/search.rs b/meilisearch-http/src/index/search.rs index fbc47cd4e..208804803 100644 --- a/meilisearch-http/src/index/search.rs +++ b/meilisearch-http/src/index/search.rs @@ -496,18 +496,19 @@ impl<'a, A: AsRef<[u8]>> Formatter<'a, A> { tokens .map(|(word, token)| { - if format_options.highlight && token.is_word() && matcher.matches(token.text()).is_some() { - let mut new_word = String::new(); - new_word.push_str(&self.marks.0); - if let Some(match_len) = matcher.matches(token.text()) { + if let Some(match_len) = matcher.matches(token.text()) { + if format_options.highlight && token.is_word() { + let mut new_word = String::new(); + + new_word.push_str(&self.marks.0); new_word.push_str(&word[..match_len]); new_word.push_str(&self.marks.1); new_word.push_str(&word[match_len..]); + + return Cow::Owned(new_word) } - Cow::Owned(new_word) - } else { - Cow::Borrowed(word) } + Cow::Borrowed(word) }) .collect::() } From 8fc12b1526944776d90da1d2ec1ffbbfd3ea3dd8 Mon Sep 17 00:00:00 2001 From: marin Date: Mon, 21 Jun 2021 11:06:06 +0200 Subject: [PATCH 2/2] Update meilisearch-http/src/index/search.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Renault --- meilisearch-http/src/index/search.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meilisearch-http/src/index/search.rs b/meilisearch-http/src/index/search.rs index 208804803..01650c9f5 100644 --- a/meilisearch-http/src/index/search.rs +++ b/meilisearch-http/src/index/search.rs @@ -496,8 +496,8 @@ impl<'a, A: AsRef<[u8]>> Formatter<'a, A> { tokens .map(|(word, token)| { - if let Some(match_len) = matcher.matches(token.text()) { - if format_options.highlight && token.is_word() { + if format_options.highlight && token.is_word() { + if let Some(match_len) = matcher.matches(token.text()) { let mut new_word = String::new(); new_word.push_str(&self.marks.0);