blacklight 6.10.1 → 6.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +2 -2
- data/VERSION +1 -1
- data/app/controllers/concerns/blacklight/request_builders.rb +5 -2
- data/app/controllers/concerns/blacklight/search_context.rb +13 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +4 -1
- data/app/helpers/blacklight/configuration_helper_behavior.rb +4 -0
- data/app/views/catalog/_sort_widget.html.erb +1 -1
- data/blacklight.gemspec +1 -0
- data/lib/blacklight/configuration.rb +5 -1
- data/lib/blacklight/solr/response/spelling.rb +4 -2
- data/spec/controllers/blacklight/search_helper_spec.rb +8 -0
- data/spec/features/search_crawler_spec.rb +30 -0
- data/spec/views/catalog/_sort_widget.html.erb_spec.rb +43 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 741267e0943b9248b05baca938f10fe8c3454717
|
4
|
+
data.tar.gz: 333367da063309c42774d31396aadaa17480bc43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e86f64f778efb7e43db4b0acd10999bb8c151ba30f59272522354469ad79ba28b04979864d381b2532c478b28fac33e712961bd5ca85aef41a04c0849e1dbe6
|
7
|
+
data.tar.gz: b6c6bc62fa20aeb936610a14de238f99f39f66cc3597255f7ab8c440897526bd95d6aad5eecb56f43ce50716f3af4eac7700147203cd367c13ab78be7f83d3a7
|
data/.rubocop_todo.yml
CHANGED
@@ -86,12 +86,12 @@ Metrics/BlockLength:
|
|
86
86
|
Metrics/BlockNesting:
|
87
87
|
Max: 4
|
88
88
|
|
89
|
-
# Offense count: 2
|
90
89
|
# Configuration parameters: CountComments.
|
91
90
|
Metrics/ClassLength:
|
92
|
-
Max:
|
91
|
+
Max: 100
|
93
92
|
Exclude:
|
94
93
|
- 'lib/blacklight/configuration.rb'
|
94
|
+
- 'lib/blacklight/search_builder.rb'
|
95
95
|
|
96
96
|
# Offense count: 20
|
97
97
|
Metrics/CyclomaticComplexity:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
6.
|
1
|
+
6.11.0
|
@@ -29,7 +29,11 @@ module Blacklight
|
|
29
29
|
# Pagination parameters for selecting the previous and next documents
|
30
30
|
# out of a result set.
|
31
31
|
def previous_and_next_document_params(index, window = 1)
|
32
|
-
solr_params =
|
32
|
+
solr_params = blacklight_config.document_pagination_params.dup
|
33
|
+
|
34
|
+
if solr_params.empty?
|
35
|
+
solr_params[:fl] = '*'
|
36
|
+
end
|
33
37
|
|
34
38
|
if index > 0
|
35
39
|
solr_params[:start] = index - window # get one before
|
@@ -39,7 +43,6 @@ module Blacklight
|
|
39
43
|
solr_params[:rows] = 2*window # but there should be one after
|
40
44
|
end
|
41
45
|
|
42
|
-
solr_params[:fl] = '*'
|
43
46
|
solr_params[:facet] = false
|
44
47
|
solr_params
|
45
48
|
end
|
@@ -36,7 +36,9 @@ module Blacklight::SearchContext
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def find_search_session
|
39
|
-
if
|
39
|
+
if agent_is_crawler?
|
40
|
+
nil
|
41
|
+
elsif params[:search_context].present?
|
40
42
|
find_or_initialize_search_session_from_params JSON.parse(params[:search_context])
|
41
43
|
elsif params[:search_id].present?
|
42
44
|
begin
|
@@ -63,6 +65,16 @@ module Blacklight::SearchContext
|
|
63
65
|
false
|
64
66
|
end
|
65
67
|
|
68
|
+
##
|
69
|
+
# Determine if the current request is coming from an anonymous bot
|
70
|
+
# or search crawler
|
71
|
+
#
|
72
|
+
def agent_is_crawler?
|
73
|
+
crawler_proc = blacklight_config.crawler_detector
|
74
|
+
return false if crawler_proc.nil? || current_user.present?
|
75
|
+
crawler_proc.call(request)
|
76
|
+
end
|
77
|
+
|
66
78
|
def find_or_initialize_search_session_from_params params
|
67
79
|
params_copy = params.reject { |k,v| blacklisted_search_session_params.include?(k.to_sym) or v.blank? }
|
68
80
|
|
@@ -17,7 +17,10 @@ module Blacklight::BlacklightHelperBehavior
|
|
17
17
|
#
|
18
18
|
# @return [String] the application name
|
19
19
|
def application_name
|
20
|
-
|
20
|
+
if Rails.application.config.respond_to? :application_name
|
21
|
+
Deprecation.warn(self, "BlacklightHelper#application_name will no longer delegate to config.application_name in version 7.0. Set the i18n for blacklight.application_name instead")
|
22
|
+
return Rails.application.config.application_name
|
23
|
+
end
|
21
24
|
|
22
25
|
t('blacklight.application_name')
|
23
26
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Blacklight::ConfigurationHelperBehavior
|
3
|
+
extend Deprecation
|
4
|
+
self.deprecation_horizon = 'blacklight 7.x'
|
5
|
+
|
3
6
|
##
|
4
7
|
# Index fields to display for a type of document
|
5
8
|
#
|
@@ -13,6 +16,7 @@ module Blacklight::ConfigurationHelperBehavior
|
|
13
16
|
def sort_fields
|
14
17
|
active_sort_fields.map { |key, x| [x.label, x.key] }
|
15
18
|
end
|
19
|
+
deprecation_deprecate :sort_fields
|
16
20
|
|
17
21
|
def active_sort_fields
|
18
22
|
blacklight_config.sort_fields.select { |sort_key, field_config| should_render_field?(field_config) }
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% if show_sort_and_per_page? and
|
1
|
+
<% if show_sort_and_per_page? and active_sort_fields.many? %>
|
2
2
|
<div id="sort-dropdown" class="btn-group">
|
3
3
|
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
|
4
4
|
<%= t('blacklight.search.sort.label', :field =>current_sort_field.label) %> <span class="caret"></span>
|
data/blacklight.gemspec
CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
|
28
28
|
s.add_dependency "rails", ">= 4.2", "< 6"
|
29
29
|
s.add_dependency "globalid"
|
30
|
+
s.add_dependency "jbuilder"
|
30
31
|
s.add_dependency "nokogiri", "~>1.6" # XML Parser
|
31
32
|
s.add_dependency "kaminari", ">= 0.15" # the pagination (page 1,2,3, etc..) of our search results
|
32
33
|
s.add_dependency "rsolr", ">= 1.0.6", "< 3" # Library for interacting with rSolr.
|
@@ -56,6 +56,7 @@ module Blacklight
|
|
56
56
|
#facet: false,
|
57
57
|
#rows: 1
|
58
58
|
},
|
59
|
+
document_pagination_params: {},
|
59
60
|
##
|
60
61
|
# == Response models
|
61
62
|
## Class for sending and receiving requests from a search index
|
@@ -137,7 +138,10 @@ module Blacklight
|
|
137
138
|
# how many searches to save in session history
|
138
139
|
search_history_window: 100,
|
139
140
|
default_facet_limit: 10,
|
140
|
-
default_more_limit: 20
|
141
|
+
default_more_limit: 20,
|
142
|
+
# proc for determining whether the session is a crawler/bot
|
143
|
+
# ex.: crawler_detector: lambda { |req| req.env['HTTP_USER_AGENT'] =~ /bot/ }
|
144
|
+
crawler_detector: nil
|
141
145
|
}
|
142
146
|
end
|
143
147
|
end
|
@@ -73,10 +73,12 @@ module Blacklight::Solr::Response::Spelling
|
|
73
73
|
return unless spellcheck && spellcheck[:suggestions]
|
74
74
|
suggestions = spellcheck[:suggestions]
|
75
75
|
|
76
|
-
if suggestions.index("collation")
|
76
|
+
if suggestions.is_a?(Array) && suggestions.index("collation")
|
77
|
+
# solr < 5 response
|
77
78
|
suggestions[suggestions.index("collation") + 1]
|
78
79
|
elsif spellcheck.key?("collations")
|
79
|
-
|
80
|
+
# solr 5+ response
|
81
|
+
spellcheck['collations'].last if spellcheck.key?("collations")
|
80
82
|
end
|
81
83
|
end
|
82
84
|
end
|
@@ -458,5 +458,13 @@ describe Blacklight::SearchHelper do
|
|
458
458
|
expect(docs.last).to be_nil
|
459
459
|
expect(docs.first).to be_nil
|
460
460
|
end
|
461
|
+
|
462
|
+
it 'allows the query parameters to be customized using configuration' do
|
463
|
+
blacklight_config.document_pagination_params[:fl] = 'id,format'
|
464
|
+
|
465
|
+
response, docs = subject.get_previous_and_next_documents_for_search(0, :q => '')
|
466
|
+
|
467
|
+
expect(docs.last.to_h).to eq @all_docs[1].to_h.slice('id', 'format')
|
468
|
+
end
|
461
469
|
end
|
462
470
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "Search History Page" do
|
4
|
+
|
5
|
+
describe "crawler search" do
|
6
|
+
let(:original_proc) { ::CatalogController.blacklight_config.crawler_detector }
|
7
|
+
|
8
|
+
before do
|
9
|
+
::CatalogController.blacklight_config.crawler_detector = lambda { |req| req.env['HTTP_USER_AGENT'] =~ /Googlebot/ }
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
::CatalogController.blacklight_config.crawler_detector = original_proc
|
14
|
+
end
|
15
|
+
|
16
|
+
it "remembers human searches" do
|
17
|
+
visit root_path
|
18
|
+
fill_in "q", with: 'chicken'
|
19
|
+
expect { click_button 'search' }.to change { Search.count }.by(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "doesn't remember bot searches" do
|
23
|
+
page.driver.header('User-Agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')
|
24
|
+
visit root_path
|
25
|
+
fill_in "q", with: 'chicken'
|
26
|
+
expect { click_button 'search' }.to_not change { Search.count }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "catalog/_sort_widget" do
|
4
|
+
let(:blacklight_config) { Blacklight::Configuration.new }
|
5
|
+
let(:response) { instance_double(Blacklight::Solr::Response, empty?: false, sort: 'one') }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(view).to receive_messages(blacklight_config: blacklight_config)
|
9
|
+
assign(:response, response)
|
10
|
+
controller.request.path_parameters[:action] = 'index'
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with no sort fields configured' do
|
14
|
+
it 'renders nothing' do
|
15
|
+
render
|
16
|
+
expect(rendered).to be_blank
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with a single sort field configured' do
|
21
|
+
before do
|
22
|
+
blacklight_config.add_sort_field 'one'
|
23
|
+
end
|
24
|
+
it 'renders nothing' do
|
25
|
+
render
|
26
|
+
expect(rendered).to be_blank
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with multiple sort fields configured' do
|
31
|
+
before do
|
32
|
+
blacklight_config.add_sort_field 'one'
|
33
|
+
blacklight_config.add_sort_field 'two'
|
34
|
+
end
|
35
|
+
it 'renders a dropdown with the various options' do
|
36
|
+
render
|
37
|
+
|
38
|
+
expect(rendered).to have_button 'One'
|
39
|
+
expect(rendered).to have_link 'One'
|
40
|
+
expect(rendered).to have_link 'Two'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
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: 6.
|
4
|
+
version: 6.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind
|
@@ -17,7 +17,7 @@ authors:
|
|
17
17
|
autorequire:
|
18
18
|
bindir: exe
|
19
19
|
cert_chain: []
|
20
|
-
date: 2017-
|
20
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rails
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: jbuilder
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: nokogiri
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -635,6 +649,7 @@ files:
|
|
635
649
|
- spec/features/record_view_spec.rb
|
636
650
|
- spec/features/saved_searches_spec.rb
|
637
651
|
- spec/features/search_context_spec.rb
|
652
|
+
- spec/features/search_crawler_spec.rb
|
638
653
|
- spec/features/search_filters_spec.rb
|
639
654
|
- spec/features/search_formats_spec.rb
|
640
655
|
- spec/features/search_history_spec.rb
|
@@ -717,6 +732,7 @@ files:
|
|
717
732
|
- spec/views/catalog/_show_sidebar.erb_spec.rb
|
718
733
|
- spec/views/catalog/_show_tools.html.erb_spec.rb
|
719
734
|
- spec/views/catalog/_sort_and_per_page.html.erb_spec.rb
|
735
|
+
- spec/views/catalog/_sort_widget.html.erb_spec.rb
|
720
736
|
- spec/views/catalog/_thumbnail_default.erb_spec.rb
|
721
737
|
- spec/views/catalog/_view_type_group.html.erb_spec.rb
|
722
738
|
- spec/views/catalog/facet.html.erb_spec.rb
|
@@ -774,6 +790,7 @@ test_files:
|
|
774
790
|
- spec/features/record_view_spec.rb
|
775
791
|
- spec/features/saved_searches_spec.rb
|
776
792
|
- spec/features/search_context_spec.rb
|
793
|
+
- spec/features/search_crawler_spec.rb
|
777
794
|
- spec/features/search_filters_spec.rb
|
778
795
|
- spec/features/search_formats_spec.rb
|
779
796
|
- spec/features/search_history_spec.rb
|
@@ -856,6 +873,7 @@ test_files:
|
|
856
873
|
- spec/views/catalog/_show_sidebar.erb_spec.rb
|
857
874
|
- spec/views/catalog/_show_tools.html.erb_spec.rb
|
858
875
|
- spec/views/catalog/_sort_and_per_page.html.erb_spec.rb
|
876
|
+
- spec/views/catalog/_sort_widget.html.erb_spec.rb
|
859
877
|
- spec/views/catalog/_thumbnail_default.erb_spec.rb
|
860
878
|
- spec/views/catalog/_view_type_group.html.erb_spec.rb
|
861
879
|
- spec/views/catalog/facet.html.erb_spec.rb
|