@@ -113,6 +113,72 @@ def test_custom_search_params_with_string_list(index_with_documents):
113
113
assert 'title' in response ['hits' ][0 ]['_formatted' ]
114
114
assert 'overview' in response ['hits' ][0 ]['_formatted' ]
115
115
116
+ def test_custom_search_params_with_crop_marker (index_with_documents ):
117
+ """Tests search with a list of one string in query params."""
118
+ response = index_with_documents ().search (
119
+ 'dragon' ,
120
+ {
121
+ 'limit' : 1 ,
122
+ 'attributesToCrop' : ['overview' ],
123
+ 'cropLength' : 10 ,
124
+ }
125
+ )
126
+ assert isinstance (response , dict )
127
+ assert len (response ['hits' ]) == 1
128
+ assert '_formatted' in response ['hits' ][0 ]
129
+ assert 'overview' in response ['hits' ][0 ]['_formatted' ]
130
+ assert response ['hits' ][0 ]['_formatted' ]['overview' ].count (' ' ) < 10
131
+ assert response ['hits' ][0 ]['_formatted' ]['overview' ].count ('…' ) == 2
132
+
133
+ def test_custom_search_params_with_customized_crop_marker (index_with_documents ):
134
+ """Tests search with a list of one string in query params."""
135
+ response = index_with_documents ().search (
136
+ 'dragon' ,
137
+ {
138
+ 'limit' : 1 ,
139
+ 'attributesToCrop' : ['overview' ],
140
+ 'cropLength' : 10 ,
141
+ 'cropMarker' : '(ꈍᴗꈍ)' ,
142
+ }
143
+ )
144
+ assert isinstance (response , dict )
145
+ assert len (response ['hits' ]) == 1
146
+ assert '_formatted' in response ['hits' ][0 ]
147
+ assert 'overview' in response ['hits' ][0 ]['_formatted' ]
148
+ assert response ['hits' ][0 ]['_formatted' ]['overview' ].count ('(ꈍᴗꈍ)' ) == 2
149
+
150
+ def test_custom_search_params_with_highlight_tag (index_with_documents ):
151
+ """Tests search with a list of one string in query params."""
152
+ response = index_with_documents ().search (
153
+ 'dragon' ,
154
+ {
155
+ 'limit' : 1 ,
156
+ 'attributesToHighlight' : ['*' ],
157
+ }
158
+ )
159
+ assert isinstance (response , dict )
160
+ assert len (response ['hits' ]) == 1
161
+ assert '_formatted' in response ['hits' ][0 ]
162
+ assert 'title' in response ['hits' ][0 ]['_formatted' ]
163
+ assert response ['hits' ][0 ]['_formatted' ]['title' ] == 'How to Train Your <em>Dragon</em>: The Hidden World'
164
+
165
+ def test_custom_search_params_with_customized_highlight_tag (index_with_documents ):
166
+ """Tests search with a list of one string in query params."""
167
+ response = index_with_documents ().search (
168
+ 'dragon' ,
169
+ {
170
+ 'limit' : 1 ,
171
+ 'attributesToHighlight' : ['*' ],
172
+ 'highlightPreTag' : '(⊃。•́‿•̀。)⊃ ' ,
173
+ 'highlightPostTag' : ' ⊂(´• ω •`⊂)' ,
174
+ }
175
+ )
176
+ assert isinstance (response , dict )
177
+ assert len (response ['hits' ]) == 1
178
+ assert '_formatted' in response ['hits' ][0 ]
179
+ assert 'title' in response ['hits' ][0 ]['_formatted' ]
180
+ assert response ['hits' ][0 ]['_formatted' ]['title' ] == 'How to Train Your (⊃。•́‿•̀。)⊃ Dragon ⊂(´• ω •`⊂): The Hidden World'
181
+
116
182
def test_custom_search_params_with_facets_distribution (index_with_documents ):
117
183
index = index_with_documents ()
118
184
update = index .update_filterable_attributes (['genre' ])
0 commit comments