Skip to content

Commit be72894

Browse files
Merge #1730
1730: v0.28: Smart cropping r=guimachiavelli a=guimachiavelli Closes #1687 Co-authored-by: gui machiavelli <[email protected]> Co-authored-by: gui machiavelli <[email protected]>
2 parents 52dcfd0 + 3cd5718 commit be72894

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
@@ -440,7 +440,17 @@ Optionally, you can indicate a custom crop length for any attributes given to `a
440440

441441
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).
442442

443-
**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.
443+
#### Cropping algorithm
444+
445+
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.`
446+
447+
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.`
448+
449+
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.`
450+
451+
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`.
452+
453+
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 …`.
444454

445455
#### Example
446456

@@ -510,7 +520,7 @@ When searching for `shifu`, you can use `cropMarker` to change the default `…`
510520
"id": 50393,
511521
"title": "Kung Fu Panda Holiday",
512522
"poster": "https://image.tmdb.org/t/p/w1280/gp18R42TbSUlw9VnXFqyecm52lq.jpg",
513-
"overview": "[…]villager. But this year Shifu informs Po that as Dragon[…]",
523+
"overview": "[…]But this year Shifu informs Po that as Dragon Warrior,[…]",
514524
"release_date": 1290729600
515525
}
516526
}

0 commit comments

Comments
 (0)