From 556a908fd6cbf130f003ca81d5f87c9ea46d4215 Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Wed, 15 Jun 2022 18:47:01 +0200 Subject: [PATCH 1/4] update cropping behaviour --- reference/api/search.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/reference/api/search.md b/reference/api/search.md index 491fc9aa8b..6a8c1773e4 100644 --- a/reference/api/search.md +++ b/reference/api/search.md @@ -460,7 +460,17 @@ Optionally, you can indicate a custom crop length for any attributes given to `a Instead of supplying individual attributes, you can provide `["*"]` as a wildcard: `attributesToCrop=["*"]`. This causes `_formatted` to include the cropped values of all attributes present in [`attributesToRetrieve`](#attributes-to-retrieve). -**Meilisearch crops around the first occurrence of any one of the terms present in the search query.** If Meilisearch does not find any query terms in a field, cropping begins at the first word in that field. +#### Cropping rules + +Suppose you have a field containing the following string: `Donatello is a skilled and smart turtle. Leonardo is the most skilled turtle. Raphael is the strongest turtle.` + +Meilisearch takes sentence context in consideration when cropping. For example, if your search term is `Leonardo` and your `cropLength` is 6, Meilisearch will prioritize keeping the sentence together and return: `Leonardo is the most skilled turtle.` + +If a query contains only a single search term, Meilisearch crops around the first occurrence of that term. If you search for `turtle` and your `cropLength` is 7, Meilisearch will return the first instance of that word: `Donatello is a skilled and smart turtle.` + +If a query contains multiple search terms, Meilisearch centers the crop around the largest number of unique matches, giving priority to terms that are closer to each other and follow the original query order. If you search for `skilled turtle` with a `cropLength` of 6, Meilisearch will return `Leonardo is the most skilled turtle`. + +If Meilisearch does not find any query terms in a field, cropping begins at the first word in that field. If you search for `Michelangelo` with a `cropLength` of 4, Meilisearch will return `Donatello is a skilled …`. #### Example @@ -530,7 +540,7 @@ When searching for `shifu`, you can use `cropMarker` to change the default `…` "id": 50393, "title": "Kung Fu Panda Holiday", "poster": "https://image.tmdb.org/t/p/w1280/gp18R42TbSUlw9VnXFqyecm52lq.jpg", - "overview": "[…]villager. But this year Shifu informs Po that as Dragon[…]", + "overview": "[…]But this year Shifu informs Po that as Dragon Warrior,[…]", "release_date": 1290729600 } } From d90113d09ccdc428332f919a01b38db597d46dc3 Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Thu, 16 Jun 2022 17:59:54 +0200 Subject: [PATCH 2/4] improve wording --- reference/api/search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/api/search.md b/reference/api/search.md index 6a8c1773e4..ffdd9e281f 100644 --- a/reference/api/search.md +++ b/reference/api/search.md @@ -464,7 +464,7 @@ Instead of supplying individual attributes, you can provide `["*"]` as a wildcar Suppose you have a field containing the following string: `Donatello is a skilled and smart turtle. Leonardo is the most skilled turtle. Raphael is the strongest turtle.` -Meilisearch takes sentence context in consideration when cropping. For example, if your search term is `Leonardo` and your `cropLength` is 6, Meilisearch will prioritize keeping the sentence together and return: `Leonardo is the most skilled turtle.` +Meilisearch respects sentence boundaries when cropping. For example, if your search term is `Leonardo` and your `cropLength` is 6, Meilisearch will prioritize keeping the sentence together and return: `Leonardo is the most skilled turtle.` If a query contains only a single search term, Meilisearch crops around the first occurrence of that term. If you search for `turtle` and your `cropLength` is 7, Meilisearch will return the first instance of that word: `Donatello is a skilled and smart turtle.` From 6fdb452cb9fe59a9df11727a189d2163a31afecd Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Wed, 29 Jun 2022 13:08:01 +0200 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com> --- reference/api/search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/api/search.md b/reference/api/search.md index ffdd9e281f..ca7c171c25 100644 --- a/reference/api/search.md +++ b/reference/api/search.md @@ -464,7 +464,7 @@ Instead of supplying individual attributes, you can provide `["*"]` as a wildcar Suppose you have a field containing the following string: `Donatello is a skilled and smart turtle. Leonardo is the most skilled turtle. Raphael is the strongest turtle.` -Meilisearch respects sentence boundaries when cropping. For example, if your search term is `Leonardo` and your `cropLength` is 6, Meilisearch will prioritize keeping the sentence together and return: `Leonardo is the most skilled turtle.` +Meilisearch tries to respect sentence boundaries when cropping. For example, if your search term is `Leonardo` and your `cropLength` is 6, Meilisearch will prioritize keeping the sentence together and return: `Leonardo is the most skilled turtle.` If a query contains only a single search term, Meilisearch crops around the first occurrence of that term. If you search for `turtle` and your `cropLength` is 7, Meilisearch will return the first instance of that word: `Donatello is a skilled and smart turtle.` From 3cd5718fd4c40b8da64f3e340aac6bf39103ada8 Mon Sep 17 00:00:00 2001 From: gui machiavelli Date: Wed, 29 Jun 2022 13:33:58 +0200 Subject: [PATCH 4/4] smart cropping: address review feedback --- reference/api/search.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/api/search.md b/reference/api/search.md index ca7c171c25..01713ab57a 100644 --- a/reference/api/search.md +++ b/reference/api/search.md @@ -460,7 +460,7 @@ Optionally, you can indicate a custom crop length for any attributes given to `a Instead of supplying individual attributes, you can provide `["*"]` as a wildcard: `attributesToCrop=["*"]`. This causes `_formatted` to include the cropped values of all attributes present in [`attributesToRetrieve`](#attributes-to-retrieve). -#### Cropping rules +#### Cropping algorithm Suppose you have a field containing the following string: `Donatello is a skilled and smart turtle. Leonardo is the most skilled turtle. Raphael is the strongest turtle.` @@ -470,7 +470,7 @@ If a query contains only a single search term, Meilisearch crops around the firs If a query contains multiple search terms, Meilisearch centers the crop around the largest number of unique matches, giving priority to terms that are closer to each other and follow the original query order. If you search for `skilled turtle` with a `cropLength` of 6, Meilisearch will return `Leonardo is the most skilled turtle`. -If Meilisearch does not find any query terms in a field, cropping begins at the first word in that field. If you search for `Michelangelo` with a `cropLength` of 4, Meilisearch will return `Donatello is a skilled …`. +If Meilisearch does not find any query terms in a field, cropping begins at the first word in that field. If you search for `Michelangelo` with a `cropLength` of 4 and this string is present in another field, Meilisearch will return `Donatello is a skilled …`. #### Example