blacklight 4.8.0 → 4.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/views/catalog/_facet_limit.html.erb +6 -6
- data/blacklight.gemspec +1 -0
- data/lib/blacklight/solr/facet_paginator.rb +54 -30
- data/spec/lib/facet_paginator_spec.rb +51 -59
- data/spec/spec_helper.rb +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ea490616aa86b3b39a0189cbc5a5367c443085d
|
4
|
+
data.tar.gz: 9997faba251e860106a7d5cd144298f6126d7653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbf5727a785c3e85e3fc29b9dae71f8ee244ccda246cca9d1ae25999fafc2de3ff94fc1e396cff6ce4181a46c53e5cc3940fa94c29b4b02521cae98da897e9b5
|
7
|
+
data.tar.gz: 83c06a38785804fb67995acbd2771a2bde1cfac55201b28f25d0ee86ca386b6e5ef1cc432c235c619e270a88d5ef73ac16c458b11b8296468e571f502065879f
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.9.0
|
@@ -1,14 +1,14 @@
|
|
1
1
|
<ul>
|
2
|
-
<% paginator =
|
3
|
-
Blacklight::Solr::FacetPaginator.new(display_facet.items,
|
2
|
+
<% paginator =
|
3
|
+
Blacklight::Solr::FacetPaginator.new(display_facet.items,
|
4
4
|
:limit => facet_limit_for(solr_field))
|
5
5
|
%>
|
6
6
|
<% paginator.items.each do |item| -%>
|
7
7
|
<li>
|
8
|
-
<% if facet_in_params?( solr_field, item.value ) %>
|
9
|
-
<%= render_selected_facet_value(solr_field, item) %>
|
10
|
-
<% else %>
|
11
|
-
<%= render_facet_value(solr_field, item) %>
|
8
|
+
<% if facet_in_params?( solr_field, item.value ) %>
|
9
|
+
<%= render_selected_facet_value(solr_field, item) %>
|
10
|
+
<% else %>
|
11
|
+
<%= render_facet_value(solr_field, item) %>
|
12
12
|
<% end -%>
|
13
13
|
</li>
|
14
14
|
<% end %>
|
data/blacklight.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_dependency "deprecation", "~> 0.1"
|
32
32
|
s.add_development_dependency "jettywrapper", ">= 1.4.1"
|
33
33
|
s.add_development_dependency "rspec-rails", "~> 3.0"
|
34
|
+
s.add_development_dependency "rspec-its"
|
34
35
|
s.add_development_dependency 'engine_cart', "~> 2.0"
|
35
36
|
s.add_development_dependency "equivalent-xml"
|
36
37
|
end
|
@@ -12,6 +12,10 @@ module Blacklight::Solr
|
|
12
12
|
# so we cannot know how many "pages" there are.
|
13
13
|
#
|
14
14
|
class FacetPaginator
|
15
|
+
extend Deprecation
|
16
|
+
|
17
|
+
self.deprecation_horizon = 'blacklight version 6.0.0'
|
18
|
+
|
15
19
|
# What request keys will we use for the parameters need. Need to
|
16
20
|
# make sure they do NOT conflict with catalog/index request params,
|
17
21
|
# and need to make them accessible in a list so we can easily
|
@@ -21,7 +25,7 @@ module Blacklight::Solr
|
|
21
25
|
class << self; attr_accessor :request_keys end # create a class method
|
22
26
|
def request_keys ; self.class.request_keys ; end # shortcut
|
23
27
|
|
24
|
-
attr_reader :
|
28
|
+
attr_reader :total_count, :items, :offset, :limit, :sort
|
25
29
|
|
26
30
|
# all_facet_values is a list of facet value objects returned by solr,
|
27
31
|
# asking solr for n+1 facet values.
|
@@ -33,54 +37,74 @@ module Blacklight::Solr
|
|
33
37
|
def initialize(all_facet_values, arguments)
|
34
38
|
# to_s.to_i will conveniently default to 0 if nil
|
35
39
|
@offset = arguments[:offset].to_s.to_i
|
36
|
-
@limit = arguments[:limit].to_s.to_i
|
40
|
+
@limit = arguments[:limit].to_s.to_i
|
37
41
|
# count is solr's default
|
38
42
|
@sort = arguments[:sort] || "count"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
@has_next = false
|
48
|
-
@has_previous = false
|
49
|
-
end
|
43
|
+
@total_count = all_facet_values.size
|
44
|
+
@items = items_for_limit(all_facet_values)
|
45
|
+
end
|
46
|
+
|
47
|
+
alias_method :total, :total_count
|
48
|
+
|
49
|
+
def prev_page
|
50
|
+
current_page - 1 unless first_page?
|
50
51
|
end
|
51
52
|
|
52
53
|
def current_page
|
53
|
-
|
54
|
+
if limit == 0 #check for divide by zero
|
55
|
+
1
|
56
|
+
else
|
57
|
+
@offset / limit + 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def next_page
|
62
|
+
current_page + 1 unless last_page?
|
54
63
|
end
|
55
64
|
|
65
|
+
#@deprecated
|
56
66
|
def has_next?
|
57
|
-
|
67
|
+
!last_page?
|
58
68
|
end
|
69
|
+
deprecation_deprecate :has_next?
|
59
70
|
|
71
|
+
#@deprecated
|
60
72
|
def has_previous?
|
61
|
-
|
73
|
+
!first_page?
|
62
74
|
end
|
75
|
+
deprecation_deprecate :has_next?
|
63
76
|
|
64
77
|
def last_page?
|
65
|
-
|
78
|
+
current_page >= total_pages
|
66
79
|
end
|
67
80
|
|
68
81
|
def first_page?
|
69
|
-
|
82
|
+
current_page == 1
|
70
83
|
end
|
71
84
|
|
85
|
+
def total_pages
|
86
|
+
if limit == 0 #check for divide by zero
|
87
|
+
1
|
88
|
+
else
|
89
|
+
(total_count.to_f / limit).ceil
|
90
|
+
end
|
91
|
+
end
|
72
92
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
93
|
+
# Pass in a desired solr facet solr key ('count' or 'index', see
|
94
|
+
# http://wiki.apache.org/solr/SimpleFacetParameters#facet.limit
|
95
|
+
# under facet.sort ), and your current request params.
|
96
|
+
# Get back params suitable to passing to an ActionHelper method for
|
97
|
+
# creating a url, to resort by that method.
|
98
|
+
def params_for_resort_url(sort_method, params)
|
99
|
+
# When resorting, we've got to reset the offset to start at beginning,
|
100
|
+
# no way to make it make sense otherwise.
|
101
|
+
params.merge(request_keys[:sort] => sort_method, request_keys[:page] => nil)
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
# setting limit to 0 implies no limit
|
106
|
+
def items_for_limit(values)
|
107
|
+
limit != 0 ? values.slice(offset, limit) : values
|
108
|
+
end
|
84
109
|
end
|
85
|
-
|
86
110
|
end
|
@@ -4,76 +4,68 @@
|
|
4
4
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
5
5
|
|
6
6
|
describe 'Blacklight::Solr::FacetPaginator' do
|
7
|
-
before(:all) do
|
8
|
-
require 'yaml'
|
9
|
-
@seven_facet_values = YAML::load("--- \n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 792\n value: Book\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 65\n value: Musical Score\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 58\n value: Serial\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 48\n value: Musical Recording\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 37\n value: Microform\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 27\n value: Thesis\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 0\n value: \n")
|
10
|
-
@six_facet_values = @seven_facet_values.slice(1,6)
|
11
|
-
@limit = 6
|
12
7
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
let(:f1) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '792', value: 'Book') }
|
9
|
+
let(:f2) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '65', value: 'Musical Score') }
|
10
|
+
let(:f3) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '58', value: 'Serial') }
|
11
|
+
let(:f4) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '48', value: 'Musical Recording') }
|
12
|
+
let(:f5) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '37', value: 'Microform') }
|
13
|
+
let(:f6) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '27', value: 'Thesis') }
|
14
|
+
let(:f7) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '0') }
|
15
|
+
let(:seven_facet_values) { [f1, f2, f3, f4, f5, f6, f7] }
|
16
|
+
let(:six_facet_values) { [f1, f2, f3, f4, f5, f6] }
|
17
|
+
let(:limit) { 6 }
|
23
18
|
|
19
|
+
context 'on the first page of two pages' do
|
20
|
+
subject { Blacklight::Solr::FacetPaginator.new(seven_facet_values, limit: limit) }
|
21
|
+
it { should be_first_page }
|
22
|
+
it { should_not be_last_page }
|
23
|
+
its(:current_page) { should eq 1 }
|
24
|
+
its(:prev_page) { should be_nil }
|
25
|
+
its(:next_page) { should eq 2 }
|
26
|
+
it 'should limit items to limit, if limit is smaller than items.length' do
|
27
|
+
expect(subject.items.size).to eq 6
|
28
|
+
end
|
24
29
|
end
|
25
|
-
it 'should not have next when there are fewer results' do
|
26
|
-
paginator = Blacklight::Solr::FacetPaginator.new(@six_facet_values, :offset => 0, :limit => @limit)
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
context 'on the last page of two pages' do
|
32
|
+
subject { Blacklight::Solr::FacetPaginator.new(seven_facet_values, offset: 6, limit: limit) }
|
33
|
+
it { should_not be_first_page }
|
34
|
+
it { should be_last_page }
|
35
|
+
its(:current_page) { should eq 2 }
|
36
|
+
its(:prev_page) { should eq 1 }
|
37
|
+
its(:next_page) { should be_nil }
|
38
|
+
it 'should return all items when limit is greater than items.length' do
|
39
|
+
expect(subject.items.size).to eq 1
|
34
40
|
end
|
35
|
-
|
36
|
-
it 'should have previous' do
|
37
|
-
expect(@paginator).to be_has_previous
|
38
|
-
end
|
39
|
-
|
40
41
|
end
|
41
|
-
it 'should not have previous when offset is 0' do
|
42
|
-
paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 0, :limit => @limit)
|
43
42
|
|
44
|
-
|
43
|
+
context 'on the first page of one page' do
|
44
|
+
subject { Blacklight::Solr::FacetPaginator.new(six_facet_values, offset: 0, limit: limit) }
|
45
|
+
it { should be_first_page }
|
46
|
+
it { should be_last_page }
|
45
47
|
end
|
46
|
-
it 'should know a manually set sort, and produce proper sort url' do
|
47
|
-
paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 100, :limit => @limit, :sort => 'index')
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
describe "params_for_resort_url" do
|
50
|
+
let(:sort_key) { Blacklight::Solr::FacetPaginator.request_keys[:sort] }
|
51
|
+
let(:page_key) { Blacklight::Solr::FacetPaginator.request_keys[:page] }
|
52
|
+
let(:paginator) { Blacklight::Solr::FacetPaginator.new(seven_facet_values, offset: 100, limit: limit, sort: 'index') }
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
it 'should return all items when limit is greater than items.length' do
|
61
|
-
paginator = Blacklight::Solr::FacetPaginator.new(@six_facet_values, :offset => 100, :limit => 6, :sort => 'index')
|
62
|
-
expect(paginator.items.length).to eq(6)
|
63
|
-
end
|
64
|
-
describe "for a nil :limit" do
|
65
|
-
before(:all) do
|
66
|
-
@paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 100, :limit => nil, :sort => 'index')
|
67
|
-
end
|
68
|
-
it 'should return all items' do
|
69
|
-
expect(@paginator.items).to eq(@seven_facet_values)
|
70
|
-
end
|
71
|
-
it 'should not has_next?' do
|
72
|
-
expect(@paginator).not_to be_has_next
|
54
|
+
it 'should know a manually set sort, and produce proper sort url' do
|
55
|
+
expect(paginator.sort).to eq 'index'
|
56
|
+
|
57
|
+
click_params = paginator.params_for_resort_url('count', {})
|
58
|
+
|
59
|
+
expect(click_params[ sort_key ]).to eq 'count'
|
60
|
+
expect(click_params[ page_key ]).to be_nil
|
73
61
|
end
|
74
|
-
|
75
|
-
|
62
|
+
end
|
63
|
+
|
64
|
+
context "for a nil :limit" do
|
65
|
+
subject { Blacklight::Solr::FacetPaginator.new(seven_facet_values, offset: 0, limit: nil) }
|
66
|
+
it "should return all the items" do
|
67
|
+
expect(subject.items).to eq seven_facet_values
|
76
68
|
end
|
77
69
|
end
|
78
|
-
|
70
|
+
|
79
71
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacklight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind
|
@@ -17,7 +17,7 @@ authors:
|
|
17
17
|
autorequire:
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
|
-
date: 2018-
|
20
|
+
date: 2018-10-01 00:00:00.000000000 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rails
|
@@ -157,6 +157,20 @@ dependencies:
|
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '3.0'
|
160
|
+
- !ruby/object:Gem::Dependency
|
161
|
+
name: rspec-its
|
162
|
+
requirement: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
160
174
|
- !ruby/object:Gem::Dependency
|
161
175
|
name: engine_cart
|
162
176
|
requirement: !ruby/object:Gem::Requirement
|
@@ -566,7 +580,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
566
580
|
version: '0'
|
567
581
|
requirements: []
|
568
582
|
rubyforge_project: blacklight
|
569
|
-
rubygems_version: 2.
|
583
|
+
rubygems_version: 2.6.11
|
570
584
|
signing_key:
|
571
585
|
specification_version: 4
|
572
586
|
summary: Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr)
|