Skip to content

Commit 2a56192

Browse files
committed
Add support to the new cropping and highlighting behaviors (#319)
1 parent e4c0768 commit 2a56192

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

spec/meilisearch/index/search/attributes_to_crop_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@
1212

1313
before { index.add_documents!(document) }
1414

15+
it 'searches with default cropping params' do
16+
response = index.search('galaxy', attributesToCrop: ['*'], cropLength: 6)
17+
18+
expect(response.dig('hits', 0, '_formatted', 'description')).to eq('…Guide to the Galaxy is a…')
19+
end
20+
21+
it 'searches with custom crop markers' do
22+
response = index.search('galaxy', attributesToCrop: ['*'], cropLength: 6, cropMarker: '(ꈍᴗꈍ)')
23+
24+
expect(response.dig('hits', 0, '_formatted', 'description')).to eq('(ꈍᴗꈍ)Guide to the Galaxy is a(ꈍᴗꈍ)')
25+
end
26+
27+
it 'searches with mixed highlight and crop config' do
28+
response = index.search(
29+
'galaxy',
30+
attributesToHighlight: ['*'],
31+
attributesToCrop: ['*'],
32+
highlightPreTag: '<span class="bold">'
33+
)
34+
35+
expect(response.dig('hits', 0, '_formatted', 'description')).to \
36+
eq("…Hitchhiker's Guide to the <span class=\"bold\">Galaxy</em> is a comedy science…")
37+
end
38+
39+
it 'searches with highlight tags' do
40+
response = index.search(
41+
'galaxy',
42+
attributesToHighlight: ['*'],
43+
highlightPreTag: '<span>',
44+
highlightPostTag: '</span>'
45+
)
46+
47+
expect(response.dig('hits', 0, '_formatted', 'description')).to include('<span>Galaxy</span>')
48+
end
49+
1550
it 'does a custom search with attributes to crop' do
1651
response = index.search('galaxy', { attributesToCrop: ['description'], cropLength: 6 })
1752
expect(response['hits'].first).to have_key('_formatted')

0 commit comments

Comments
 (0)