Permalink
Browse files

[#78785104] Fix image search pagination

- This is a stopgap fix until we figure out what changes we want to make to the API w/r/t the "total" field, as we don't have an inexpensive way of determining the total number of buckets. elastic/elasticsearch#4915
  • Loading branch information...
loren committed Sep 15, 2014
1 parent 773a3ec commit b12eb198c900d0d1a00c06a017477114b003489c
Showing with 6 additions and 7 deletions.
  1. +1 −2 app/models/image_search.rb
  2. +4 −4 app/models/image_search_results.rb
  3. +1 −1 app/queries/top_hits.rb
@@ -38,8 +38,7 @@ def execute_client_search
top_hits_query = TopHits.new(@query, @size, @from, @flickr_groups, @flickr_users, @instagram_profiles)
params = { preference: '_local', index: IMAGE_INDEXES, body: top_hits_query.query_body, search_type: "count" }
result = Elasticsearch::Persistence.client.search(params)
result['hits']['offset'] = @from
ImageSearchResults.new(result, @size)
ImageSearchResults.new(result, @from, @size)
end
def normalize_profile_names(profile_names)
@@ -3,10 +3,10 @@ class ImageSearchResults
Image = Struct.new(:type, :title, :url, :thumbnail_url, :taken_at)
def initialize(result, window_size = 0)
@total = result['hits']['total']
@offset = result['hits']['offset']
@results = extract_results(extract_hits(result['aggregations']['album_agg']['buckets'].last(window_size)))
def initialize(result, offset = 0, window_size = 0)
@total = result['aggregations']['album_agg']['buckets'].size
@offset = offset
@results = extract_results(extract_hits(result['aggregations']['album_agg']['buckets'].slice(offset, window_size)))
@suggestion = extract_suggestion(result['suggest']['suggestion']) if result['suggest']
end
View
@@ -27,7 +27,7 @@ def aggs(json)
json.order do
json.top_score "desc"
end
json.size @from + @size
json.size @from + @size + 1
end
json.aggs do
json.top_image_hits do

0 comments on commit b12eb19

Please sign in to comment.