Skip to content

Commit

Permalink
Don't show "more" link for every facet.
Browse files Browse the repository at this point in the history
Show "more" link when the facet limit is set to `true` or an integer
value. Fixes #958
  • Loading branch information
jcoyne committed Aug 4, 2014
1 parent 1334888 commit f7a48e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/blacklight/solr/facet_paginator.rb
Expand Up @@ -37,7 +37,7 @@ def request_keys ; self.class.request_keys ; end # shortcut
def initialize(all_facet_values, arguments)
# to_s.to_i will conveniently default to 0 if nil
@offset = arguments[:offset].to_s.to_i
@limit = arguments[:limit].to_s.to_i
@limit = arguments[:limit]
# count is solr's default
@sort = arguments[:sort] || "count"

Expand Down Expand Up @@ -82,7 +82,7 @@ def has_previous?
deprecation_deprecate :has_next?

def last_page?
total_count <= limit
limit.nil? || total_count <= limit
end

def first_page?
Expand Down Expand Up @@ -112,10 +112,10 @@ def as_json(_ = nil)
end

private
# setting limit to 0 implies no limit
# setting limit to nil implies no limit
# @return an array of facets on the page
def items_for_limit(values)
limit == 0 ? values : values.take(limit)
limit.nil? ? values : values.take(limit)
end
end
end
8 changes: 4 additions & 4 deletions lib/blacklight/solr_helper.rb
Expand Up @@ -327,8 +327,8 @@ def get_opensearch_response(field=nil, extra_controller_params={})
a << response.documents.map {|doc| doc[solr_params[:fl]].to_s }
end


DEFAULT_FACET_LIMIT = 10

# Look up facet limit for given facet_field. Will look at config, and
# if config is 'true' will look up from Solr @response if available. If
# no limit is avaialble, returns nil. Used from #solr_search_params
Expand All @@ -349,8 +349,8 @@ def facet_limit_for(facet_field)
else
limit.to_i - 1 # we added 1 to find out if we needed to paginate
end
elsif (facet.limit and facet.limit != true)
facet.limit
elsif facet.limit
facet.limit == true ? DEFAULT_FACET_LIMIT : facet.limit
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/lib/blacklight/facet_paginator_spec.rb
Expand Up @@ -75,12 +75,13 @@
it "should return all the items" do
expect(subject.items).to eq seven_facet_values
end
it { should be_last_page }
end

describe "#as_json" do
subject { Blacklight::Solr::FacetPaginator.new([f1], offset: 0, limit: nil).as_json }
it "should be well structured" do
expect(subject).to eq("items" => [{"hits"=>"792", "value"=>"Book"}], "limit" => 0,
expect(subject).to eq("items" => [{"hits"=>"792", "value"=>"Book"}], "limit" => nil,
"offset" => 0, "sort" => "count")
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/lib/blacklight/solr_helper_spec.rb
Expand Up @@ -1224,9 +1224,8 @@ def logger
expect(subject.facet_limit_for("subject_topic_facet")).to be_nil

expect(subject.solr_search_params).not_to have_key(:"f.subject_topic_facet.facet.limit")

end

describe "for 'true' configured values" do
let(:blacklight_config) do
config = Blacklight::Configuration.new
Expand All @@ -1249,6 +1248,9 @@ def logger
subject.instance_variable_set(:@response, @response)
expect(subject.facet_limit_for("language_facet")).to eq 15
end
it "should default to 10" do
expect(subject.facet_limit_for("language_facet")).to eq 10
end
end
end

Expand Down

0 comments on commit f7a48e8

Please sign in to comment.