|
12 | 12 |
|
13 | 13 | before { index.add_documents!(document) } |
14 | 14 |
|
| 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 | + |
15 | 50 | it 'does a custom search with attributes to crop' do |
16 | | - response = index.search('galaxy', { attributesToCrop: ['description'], cropLength: 15 }) |
| 51 | + response = index.search('galaxy', { attributesToCrop: ['description'], cropLength: 6 }) |
17 | 52 | expect(response['hits'].first).to have_key('_formatted') |
18 | | - expect(response['hits'].first['_formatted']['description']).to eq('s Guide to the Galaxy is a comedy science') |
| 53 | + expect(response['hits'].first['_formatted']['description']).to eq('…Guide to the Galaxy is a…') |
19 | 54 | end |
20 | 55 |
|
21 | 56 | it 'does a placehodler search with attributes to crop' do |
22 | | - response = index.search('', { attributesToCrop: ['description'], cropLength: 20 }) |
| 57 | + response = index.search('', { attributesToCrop: ['description'], cropLength: 5 }) |
23 | 58 | expect(response['hits'].first).to have_key('_formatted') |
24 | 59 | expect(response['hits'].first['description']).to eq(document[:description]) |
25 | | - expect(response['hits'].first['_formatted']['description']).to eq("The Hitchhiker\'s Guide") |
| 60 | + expect(response['hits'].first['_formatted']['description']).to eq("The Hitchhiker\'s Guide to…") |
26 | 61 | end |
27 | 62 | end |
0 commit comments