File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -191,7 +191,10 @@ def search(query, options = {})
191191 parsed_options = Utils . transform_attributes ( { q : query . to_s } . merge ( options . compact ) )
192192
193193 response = http_post "/indexes/#{ @uid } /search" , parsed_options
194- response [ 'nbHits' ] ||= response [ 'estimatedTotalHits' ]
194+
195+ if !response . key? ( 'totalPages' )
196+ response [ 'nbHits' ] ||= response [ 'estimatedTotalHits' ]
197+ end
195198
196199 response
197200 end
Original file line number Diff line number Diff line change 6969 expect ( response [ 'hits' ] . first [ 'objectId' ] ) . to eq ( 4 )
7070 expect ( response [ 'hits' ] . first ) . not_to have_key ( '_formatted' )
7171 end
72+
73+ context 'with finite pagination params' do
74+ it 'responds with specialized fields' do
75+ response = index . search ( 'coco' , { page : 2 , hits_per_page : 2 } )
76+
77+ expect ( response . keys ) . to contain_exactly ( *FINITE_PAGINATED_SEARCH_RESPONSE_KEYS )
78+ end
79+
80+ it 'responds with specialized fields' do
81+ response = index . search ( 'coco' , { page : 2 , hitsPerPage : 2 } )
82+
83+ expect ( response . keys ) . to contain_exactly ( *FINITE_PAGINATED_SEARCH_RESPONSE_KEYS )
84+ end
85+ end
7286end
Original file line number Diff line number Diff line change 4141 'nbHits'
4242] . freeze
4343
44+ FINITE_PAGINATED_SEARCH_RESPONSE_KEYS = [
45+ 'hits' ,
46+ 'query' ,
47+ 'processingTimeMs' ,
48+ 'hitsPerPage' ,
49+ 'page' ,
50+ 'totalPages' ,
51+ 'totalHits' ,
52+ ] . freeze
53+
4454Dir [ "#{ Dir . pwd } /spec/support/**/*.rb" ] . sort . each { |file | require file }
4555
4656RSpec . configure do |config |
You can’t perform that action at this time.
0 commit comments