Skip to content

Commit

Permalink
Merge pull request sunspot#185 from fedegl/master
Browse files Browse the repository at this point in the history
Add :offset option to facets to allow facet values pagination
  • Loading branch information
alindeman committed Apr 15, 2012
2 parents 68ff16a + 1047e31 commit 75f1e77
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sunspot/lib/sunspot/dsl/field_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def group(*field_names, &block)
# Either :count (values matching the most terms first) or :index (lexical)
# :limit<Integer>::
# The maximum number of facet rows to return
# :offset<Integer>::
# The offset from which to start returning facet rows
# :minimum_count<Integer>::
# The minimum count a facet row must have to be returned
# :zeros<Boolean>::
Expand Down
3 changes: 3 additions & 0 deletions sunspot/lib/sunspot/query/abstract_field_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def to_params
if @options[:limit]
params[qualified_param('limit')] = @options[:limit].to_i
end
if @options[:offset]
params[qualified_param('offset')] = @options[:offset].to_i
end
if @options[:prefix]
params[qualified_param('prefix')] = escape(@options[:prefix].to_s)
end
Expand Down
7 changes: 7 additions & 0 deletions sunspot/spec/api/query/faceting_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
end
connection.should have_last_search_with(:"f.category_ids_im.facet.limit" => 10)
end

it 'sets the facet offset' do
search do
facet :category_ids, :offset => 10
end
connection.should have_last_search_with(:"f.category_ids_im.facet.offset" => 10)
end

it 'sets the facet minimum count' do
search do
Expand Down
7 changes: 7 additions & 0 deletions sunspot/spec/integration/faceting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def self.test_field_type(name, attribute, field, *args)
end
search.facet(:title).rows.map { |row| row.value }.should include('zero')
end

it 'should return facet rows from an offset' do
search = Sunspot.search(Post) do
facet :title, :offset => 3
end
search.facet(:title).rows.map { |row| row.value }.should == %w(one zero)
end

it 'should return a specified minimum count' do
search = Sunspot.search(Post) do
Expand Down

0 comments on commit 75f1e77

Please sign in to comment.