Skip to content

Commit 556a908

Browse files
update cropping behaviour
1 parent c475ae5 commit 556a908

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

reference/api/search.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,17 @@ Optionally, you can indicate a custom crop length for any attributes given to `a
460460

461461
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).
462462

463-
**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.
463+
#### Cropping rules
464+
465+
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.`
466+
467+
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.`
468+
469+
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.`
470+
471+
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`.
472+
473+
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 …`.
464474

465475
#### Example
466476

@@ -530,7 +540,7 @@ When searching for `shifu`, you can use `cropMarker` to change the default `…`
530540
"id": 50393,
531541
"title": "Kung Fu Panda Holiday",
532542
"poster": "https://image.tmdb.org/t/p/w1280/gp18R42TbSUlw9VnXFqyecm52lq.jpg",
533-
"overview": "[…]villager. But this year Shifu informs Po that as Dragon[…]",
543+
"overview": "[…]But this year Shifu informs Po that as Dragon Warrior,[…]",
534544
"release_date": 1290729600
535545
}
536546
}

0 commit comments

Comments
 (0)