Skip to content

Commit

Permalink
changed Paginator arguments to named arguments using hash for clarity…
Browse files Browse the repository at this point in the history
…, and becuase we're about to add another one. reasonable defaults if nil.
  • Loading branch information
Jonathan Rochkind committed Jan 21, 2010
1 parent c2c7ef0 commit 3942935
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/blacklight/solr/facets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Paginator

attr_reader :total, :items, :offset, :limit

def initialize(all_facet_values, offset, limit)
@offset = offset.to_s.to_i
@limit = limit.to_s.to_i
def initialize(all_facet_values, arguments)
@offset = arguments[:offset].to_s.to_i # will default to 0 if nil
@limit = arguments[:limit] ? arguments[:limit].to_s.to_i : 6
total = all_facet_values.size
@items = all_facet_values.slice(0, limit-1)
@has_next = total > @limit
Expand Down Expand Up @@ -47,6 +47,8 @@ def params_for_previous_url(params)

return params.merge(:offset => offset - (limit-1) )
end



end

Expand Down
10 changes: 7 additions & 3 deletions lib/blacklight/solr_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ def get_solr_response_for_doc_id(id=nil, extra_controller_params={})
end

# returns a params hash for a single facet field solr query.
# used primary by the get_facet_pagination method
# used primary by the get_facet_pagination method.
# The extra_controller_parameters match REQUEST parameters sent
# by Blacklight, so the request params can just be dropped in.
# for instance 'sort' or 'offset' instead of 'facet.sort' or 'facet.offset',
# Because that's what BL uses in request params.
def solr_facet_params(facet_field, extra_controller_params={})
input = params.deep_merge(extra_controller_params)
input[:rows] ||= 0 # We normally don't want any documents, just facet values
Expand All @@ -195,7 +199,7 @@ def solr_facet_params(facet_field, extra_controller_params={})
:phrase_filters => input[:f],
:q => input[:q],
:facets => {:fields => facet_field},
:rows => input[:rows],
:rows => input[:rows].to_i, # will defualt to - if nil
'facet.limit' => 6,
'facet.offset' => input[:offset].to_i # will default to 0 if nil
}
Expand All @@ -211,7 +215,7 @@ def get_facet_pagination(facet_field, extra_controller_params={})
response = Blacklight.solr.find(solr_params)

# Actually create the paginator!
return Blacklight::Solr::Facets::Paginator.new(response.facets.first.items, solr_params['facet.offset'], solr_params['facet.limit'])
return Blacklight::Solr::Facets::Paginator.new(response.facets.first.items, :offset => solr_params['facet.offset'], :limit => solr_params['facet.limit'])
end

# a solr query method
Expand Down

0 comments on commit 3942935

Please sign in to comment.