blacklight 5.9.4 → 5.10.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/Gemfile +1 -1
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_facets.scss +11 -10
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +14 -14
- data/app/helpers/blacklight/configuration_helper_behavior.rb +16 -10
- data/app/helpers/blacklight/facets_helper_behavior.rb +15 -14
- data/app/helpers/blacklight/url_helper_behavior.rb +1 -1
- data/app/models/bookmark.rb +1 -4
- data/app/models/search.rb +3 -6
- data/app/views/catalog/_facet_layout.html.erb +2 -2
- data/app/views/catalog/_facet_limit.html.erb +5 -3
- data/app/views/catalog/_facet_pivot.html.erb +4 -4
- data/app/views/catalog/_home_text.html.erb +8 -48
- data/app/views/catalog/_index_default.html.erb +3 -3
- data/app/views/catalog/_show_default.html.erb +3 -3
- data/app/views/catalog/_sms_form.html.erb +1 -1
- data/app/views/catalog/facet.html.erb +1 -1
- data/blacklight.gemspec +1 -1
- data/config/jetty.yml +0 -3
- data/config/locales/blacklight.de.yml +2 -0
- data/config/locales/blacklight.en.yml +2 -0
- data/config/locales/blacklight.es.yml +2 -0
- data/config/locales/blacklight.fr.yml +2 -0
- data/config/locales/blacklight.pt-BR.yml +2 -0
- data/lib/blacklight.rb +70 -26
- data/lib/blacklight/abstract_repository.rb +29 -0
- data/lib/blacklight/base.rb +7 -7
- data/lib/blacklight/bookmarks.rb +5 -5
- data/lib/blacklight/catalog.rb +34 -19
- data/lib/blacklight/catalog/search_context.rb +1 -1
- data/lib/blacklight/configuration.rb +112 -46
- data/lib/blacklight/configuration/facet_field.rb +9 -7
- data/lib/blacklight/configuration/field.rb +27 -0
- data/lib/blacklight/configuration/fields.rb +25 -20
- data/lib/blacklight/configuration/search_field.rb +6 -8
- data/lib/blacklight/configuration/solr_field.rb +3 -18
- data/lib/blacklight/configuration/sort_field.rb +6 -7
- data/lib/blacklight/document.rb +156 -0
- data/lib/blacklight/document/dublin_core.rb +41 -0
- data/lib/blacklight/document/email.rb +16 -0
- data/lib/blacklight/document/export.rb +107 -0
- data/lib/blacklight/document/extensions.rb +56 -0
- data/lib/blacklight/document/schema_org.rb +7 -0
- data/lib/blacklight/document/semantic_fields.rb +51 -0
- data/lib/blacklight/document/sms.rb +14 -0
- data/lib/blacklight/document_presenter.rb +3 -3
- data/lib/blacklight/exceptions.rb +9 -2
- data/lib/blacklight/facet.rb +21 -16
- data/lib/blacklight/request_builders.rb +60 -284
- data/lib/blacklight/routes.rb +1 -1
- data/lib/blacklight/search_builder.rb +130 -0
- data/lib/blacklight/search_helper.rb +316 -0
- data/lib/blacklight/solr.rb +1 -0
- data/lib/blacklight/solr/document.rb +4 -187
- data/lib/blacklight/solr/document/dublin_core.rb +3 -37
- data/lib/blacklight/solr/document/email.rb +4 -13
- data/lib/blacklight/solr/document/export.rb +3 -103
- data/lib/blacklight/solr/document/extensions.rb +4 -52
- data/lib/blacklight/solr/document/more_like_this.rb +1 -1
- data/lib/blacklight/solr/document/schema_org.rb +4 -4
- data/lib/blacklight/solr/document/sms.rb +4 -11
- data/lib/blacklight/solr/facet_paginator.rb +2 -2
- data/lib/blacklight/solr/search_builder.rb +264 -0
- data/lib/blacklight/solr_helper.rb +6 -261
- data/lib/blacklight/solr_repository.rb +30 -24
- data/lib/blacklight/solr_response.rb +3 -3
- data/lib/blacklight/user.rb +1 -2
- data/lib/blacklight/utils.rb +0 -23
- data/lib/generators/blacklight/controller_generator.rb +38 -0
- data/lib/generators/blacklight/document_generator.rb +20 -0
- data/lib/generators/blacklight/install_generator.rb +38 -39
- data/lib/generators/blacklight/models_generator.rb +2 -62
- data/lib/generators/blacklight/templates/catalog_controller.rb +3 -4
- data/lib/generators/blacklight/templates/config/{solr.yml → blacklight.yml} +3 -0
- data/lib/generators/blacklight/templates/config/jetty.yml +0 -3
- data/lib/generators/blacklight/templates/solr_document.rb +6 -6
- data/lib/generators/blacklight/test_support_generator.rb +1 -6
- data/lib/generators/blacklight/user_generator.rb +59 -0
- data/lib/railties/blacklight.rake +16 -7
- data/spec/controllers/catalog_controller_spec.rb +9 -15
- data/spec/features/facets_spec.rb +8 -0
- data/spec/helpers/configuration_helper_spec.rb +6 -13
- data/spec/helpers/facets_helper_spec.rb +3 -2
- data/spec/lib/blacklight/configuration_spec.rb +11 -38
- data/spec/lib/blacklight/{solr/document → document}/dublin_core_spec.rb +4 -4
- data/spec/lib/blacklight/{solr/document → document}/email_spec.rb +2 -2
- data/spec/lib/blacklight/{solr/document → document}/sms_spec.rb +2 -2
- data/spec/lib/blacklight/search_builder_spec.rb +145 -0
- data/spec/lib/blacklight/search_helper_spec.rb +775 -0
- data/spec/lib/blacklight/solr/document/more_like_this_spec.rb +1 -1
- data/spec/lib/blacklight/solr/search_builder_spec.rb +561 -0
- data/spec/lib/blacklight/solr_helper_spec.rb +5 -1291
- data/spec/lib/blacklight/solr_repository_spec.rb +13 -13
- data/spec/models/record_mailer_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- data/spec/views/catalog/_constraints.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +2 -2
- data/spec/views/catalog/index.atom.builder_spec.rb +1 -1
- data/tasks/blacklight.rake +1 -1
- data/template.demo.rb +1 -1
- metadata +33 -45
- data/doc/Adding-new-document-actions.md +0 -94
- data/doc/Atom-Responses.md +0 -90
- data/doc/Blacklight-Add-ons.md +0 -23
- data/doc/Blacklight-configuration.md +0 -411
- data/doc/Blacklight-on-Heroku.md +0 -100
- data/doc/Blacklight-out-of-the-box.md +0 -47
- data/doc/Bookmarks.md +0 -1
- data/doc/Code4Lib-2014.md +0 -94
- data/doc/Configuration---Facet-Fields.md +0 -130
- data/doc/Configuration---Results-View.md +0 -224
- data/doc/Configuration---Solr-fields.md +0 -106
- data/doc/Configuring-and-Customizing-Blacklight.md +0 -257
- data/doc/Configuring-rails-routes.md +0 -13
- data/doc/Contributing-to-Blacklight.md +0 -43
- data/doc/Examples.md +0 -120
- data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -141
- data/doc/Home.md +0 -100
- data/doc/How-to-release-a-version.md +0 -45
- data/doc/Indexing-your-data-into-solr.md +0 -36
- data/doc/Internationalization.md +0 -32
- data/doc/JSON-API.md +0 -83
- data/doc/Pagination.md +0 -52
- data/doc/Providing-your-own-view-templates.md +0 -69
- data/doc/Quickstart.md +0 -153
- data/doc/README_SOLR.md +0 -245
- data/doc/Saved-Searches.md +0 -5
- data/doc/Solr-Configuration.md +0 -154
- data/doc/Sunspot-for-indexing.md +0 -46
- data/doc/Support.md +0 -33
- data/doc/Theming.md +0 -62
- data/doc/Understanding-Rails-and-Blacklight.md +0 -75
- data/doc/User-Authentication.md +0 -60
- data/doc/_Sidebar.md +0 -9
- data/doc/testing.md +0 -58
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Blacklight::SearchBuilder do
|
|
4
|
+
let(:processor_chain) { [] }
|
|
5
|
+
let(:blacklight_config) { Blacklight::Configuration.new }
|
|
6
|
+
let(:scope) { double blacklight_config: blacklight_config }
|
|
7
|
+
subject { described_class.new processor_chain, scope }
|
|
8
|
+
describe "#with" do
|
|
9
|
+
it "should set the blacklight params" do
|
|
10
|
+
params = {}
|
|
11
|
+
subject.with(params)
|
|
12
|
+
expect(subject.blacklight_params).to eq params
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should dup the params" do
|
|
16
|
+
params = {}
|
|
17
|
+
subject.with(params).where('asdf')
|
|
18
|
+
expect(subject.blacklight_params).not_to eq params
|
|
19
|
+
expect(subject.blacklight_params[:q]).to eq 'asdf'
|
|
20
|
+
expect(params[:q]).not_to eq 'asdf'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "#processor_chain" do
|
|
25
|
+
let(:processor_chain) { [:a, :b, :c] }
|
|
26
|
+
it "should be mutable" do
|
|
27
|
+
subject.processor_chain.insert(-1, :d)
|
|
28
|
+
expect(subject.processor_chain).to match_array [:a, :b, :c, :d]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "#append" do
|
|
33
|
+
let(:processor_chain) { [:a, :b, :c] }
|
|
34
|
+
it "should provide a new search builder with the processor chain" do
|
|
35
|
+
builder = subject.append(:d, :e)
|
|
36
|
+
expect(subject.processor_chain).to eq processor_chain
|
|
37
|
+
expect(builder.processor_chain).not_to eq subject.processor_chain
|
|
38
|
+
expect(builder.processor_chain).to match_array [:a, :b, :c, :d, :e]
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "#query" do
|
|
43
|
+
it "should append the extra parameters to the result" do
|
|
44
|
+
actual = subject.query({a: 1})
|
|
45
|
+
expect(actual).to include a: 1
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "#processed_parameters" do
|
|
50
|
+
let(:processor_chain) { [:step_1] }
|
|
51
|
+
it "should try to run the processor method on the provided scope" do
|
|
52
|
+
allow(scope).to receive(:respond_to?).and_return(true)
|
|
53
|
+
allow(scope).to receive(:step_1) do |req_params, user_params|
|
|
54
|
+
req_params[:step_1] = 'scope'
|
|
55
|
+
req_params[:user_params] = user_params
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
Deprecation.silence(Blacklight::SearchBuilder) do
|
|
59
|
+
subject.with(a: 1)
|
|
60
|
+
expect(subject.processed_parameters).to include step_1: 'scope', user_params: { a: 1 }
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should try to run the processor method on the search builder" do
|
|
65
|
+
allow(subject).to receive(:step_1) do |req_params|
|
|
66
|
+
req_params[:step_1] = 'builder'
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
subject.with(a: 1)
|
|
70
|
+
expect(subject.processed_parameters).to include step_1: 'builder'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe "#blacklight_config" do
|
|
75
|
+
it "should get the blacklight_config from the scope" do
|
|
76
|
+
expect(subject.blacklight_config).to eq scope.blacklight_config
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "#page" do
|
|
81
|
+
it "should be the current user parameter page number" do
|
|
82
|
+
expect(subject.with(page: 2).send(:page)).to eq 2
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should be page 1 if not page number given" do
|
|
86
|
+
expect(subject.send(:page)).to eq 1
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "should coerce parameters to integers" do
|
|
90
|
+
expect(subject.with(page: '2b').send(:page)).to eq 2
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe "#rows" do
|
|
95
|
+
it "should be the per_page parameter" do
|
|
96
|
+
expect(subject.with(per_page: 5).send(:rows)).to eq 5
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should support the legacy 'rows' parameter" do
|
|
100
|
+
expect(subject.with(rows: 10).send(:rows)).to eq 10
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should use the provided default" do
|
|
104
|
+
expect(subject.send(:rows, 17)).to eq 17
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should be set to the configured default" do
|
|
108
|
+
blacklight_config.default_per_page = 42
|
|
109
|
+
expect(subject.send(:rows)).to eq 42
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "should default to 10" do
|
|
113
|
+
blacklight_config.default_per_page = nil
|
|
114
|
+
expect(subject.send(:rows)).to eq 10
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should limit the number of rows to the configured maximum" do
|
|
118
|
+
blacklight_config.max_per_page = 1000
|
|
119
|
+
expect(subject.send(:rows, 1001)).to eq 1000
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe "#sort" do
|
|
124
|
+
it "should pass through the sort parameter" do
|
|
125
|
+
expect(subject.with(sort: 'x').send(:sort)).to eq 'x'
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "should use the default if no sort parameter is given" do
|
|
129
|
+
blacklight_config.default_sort_field = double(sort: 'x desc')
|
|
130
|
+
expect(subject.send(:sort)).to eq 'x desc'
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "should use the requested sort field" do
|
|
134
|
+
blacklight_config.add_sort_field 'x', sort: 'x asc'
|
|
135
|
+
expect(subject.with(sort: 'x').send(:sort)).to eq 'x asc'
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
describe "#search_field" do
|
|
140
|
+
it "should use the requested search field" do
|
|
141
|
+
blacklight_config.add_search_field 'x'
|
|
142
|
+
expect(subject.with(search_field: 'x').send(:search_field)).to eq blacklight_config.search_fields['x']
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
# check the methods that do solr requests. Note that we are not testing if
|
|
5
|
+
# solr gives "correct" responses, as that's out of scope (it's a part of
|
|
6
|
+
# testing the solr code itself). We *are* testing if blacklight code sends
|
|
7
|
+
# queries to solr such that it gets appropriate results. When a user does a search,
|
|
8
|
+
# do we get data back from solr (i.e. did we properly configure blacklight code
|
|
9
|
+
# to talk with solr and get results)? when we do a document request, does
|
|
10
|
+
# blacklight code get a single document returned?)
|
|
11
|
+
#
|
|
12
|
+
describe Blacklight::SearchHelper do
|
|
13
|
+
|
|
14
|
+
let(:default_method_chain) { CatalogController.search_params_logic }
|
|
15
|
+
|
|
16
|
+
# SearchHelper is a controller layer mixin, which depends
|
|
17
|
+
# on being mixed into a class which has #params (from Rails)
|
|
18
|
+
# and #blacklight_config
|
|
19
|
+
class SearchHelperTestClass
|
|
20
|
+
include Blacklight::SearchHelper
|
|
21
|
+
|
|
22
|
+
attr_accessor :blacklight_config
|
|
23
|
+
attr_accessor :repository
|
|
24
|
+
|
|
25
|
+
def initialize blacklight_config, conn
|
|
26
|
+
self.blacklight_config = blacklight_config
|
|
27
|
+
self.repository = Blacklight::SolrRepository.new(blacklight_config)
|
|
28
|
+
self.repository.connection = conn
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def params
|
|
32
|
+
{}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
subject { SearchHelperTestClass.new blacklight_config, blacklight_solr }
|
|
37
|
+
|
|
38
|
+
let(:blacklight_config) { Blacklight::Configuration.new }
|
|
39
|
+
let(:copy_of_catalog_config) { ::CatalogController.blacklight_config.deep_copy }
|
|
40
|
+
let(:blacklight_solr) { RSolr.connect(Blacklight.connection_config) }
|
|
41
|
+
|
|
42
|
+
before(:each) do
|
|
43
|
+
@all_docs_query = ''
|
|
44
|
+
@no_docs_query = 'zzzzzzzzzzzz'
|
|
45
|
+
@single_word_query = 'include'
|
|
46
|
+
@mult_word_query = 'tibetan history'
|
|
47
|
+
# f[format][]=Book&f[language_facet][]=English
|
|
48
|
+
@single_facet = {:format=>'Book'}
|
|
49
|
+
@multi_facets = {:format=>'Book', :language_facet=>'Tibetan'}
|
|
50
|
+
@bad_facet = {:format=>'666'}
|
|
51
|
+
@subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"rows"=>"10", :"q"=>"wome"}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe "solr_search_params" do
|
|
55
|
+
it "allows customization of the filter pipeline" do
|
|
56
|
+
# Normally you'd include a new module into (eg) your CatalogController
|
|
57
|
+
# but a sub-class defininig it directly is simpler for test.
|
|
58
|
+
allow(subject).to receive(:add_foo_to_solr_params) do |solr_params, user_params|
|
|
59
|
+
solr_params[:wt] = "TESTING"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
allow(Deprecation).to receive(:warn)
|
|
63
|
+
expect(subject.solr_search_params({}, [:add_foo_to_solr_params])[:wt]).to eq "TESTING"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe "solr_facet_params" do
|
|
68
|
+
before do
|
|
69
|
+
@facet_field = 'format'
|
|
70
|
+
@generated_solr_facet_params = subject.solr_facet_params(@facet_field)
|
|
71
|
+
|
|
72
|
+
@sort_key = Blacklight::Solr::FacetPaginator.request_keys[:sort]
|
|
73
|
+
@page_key = Blacklight::Solr::FacetPaginator.request_keys[:page]
|
|
74
|
+
end
|
|
75
|
+
let(:blacklight_config) do
|
|
76
|
+
Blacklight::Configuration.new do |config|
|
|
77
|
+
config.add_facet_fields_to_solr_request!
|
|
78
|
+
config.add_facet_field 'format'
|
|
79
|
+
config.add_facet_field 'format_ordered', :sort => :count
|
|
80
|
+
config.add_facet_field 'format_limited', :limit => 5
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'sets rows to 0' do
|
|
86
|
+
expect(@generated_solr_facet_params[:rows]).to eq 0
|
|
87
|
+
end
|
|
88
|
+
it 'sets facets requested to facet_field argument' do
|
|
89
|
+
expect(@generated_solr_facet_params["facet.field".to_sym]).to eq @facet_field
|
|
90
|
+
end
|
|
91
|
+
it 'defaults offset to 0' do
|
|
92
|
+
expect(@generated_solr_facet_params[:"f.#{@facet_field}.facet.offset"]).to eq 0
|
|
93
|
+
end
|
|
94
|
+
it 'uses offset manually set, and converts it to an integer' do
|
|
95
|
+
solr_params = subject.solr_facet_params(@facet_field, @page_key => 2)
|
|
96
|
+
expect(solr_params[:"f.#{@facet_field}.facet.offset"]).to eq 20
|
|
97
|
+
end
|
|
98
|
+
it 'defaults limit to 20' do
|
|
99
|
+
solr_params = subject.solr_facet_params(@facet_field)
|
|
100
|
+
expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 21
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
describe 'if facet_list_limit is defined in controller' do
|
|
104
|
+
before do
|
|
105
|
+
allow(subject).to receive_messages facet_list_limit: 1000
|
|
106
|
+
end
|
|
107
|
+
it 'uses controller method for limit' do
|
|
108
|
+
solr_params = subject.solr_facet_params(@facet_field)
|
|
109
|
+
expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 1001
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'uses controller method for limit when a ordinary limit is set' do
|
|
113
|
+
solr_params = subject.solr_facet_params(@facet_field)
|
|
114
|
+
expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 1001
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'uses the default sort' do
|
|
119
|
+
solr_params = subject.solr_facet_params(@facet_field)
|
|
120
|
+
expect(solr_params[:"f.#{@facet_field}.facet.sort"]).to be_blank
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'uses sort provided in the parameters' do
|
|
124
|
+
solr_params = subject.solr_facet_params(@facet_field, @sort_key => "index")
|
|
125
|
+
expect(solr_params[:"f.#{@facet_field}.facet.sort"]).to eq 'index'
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "comes up with the same params as #solr_search_params to constrain context for facet list" do
|
|
129
|
+
search_params = {:q => 'tibetan history', :f=> {:format=>'Book', :language_facet=>'Tibetan'}}
|
|
130
|
+
solr_facet_params = subject.solr_facet_params('format', search_params)
|
|
131
|
+
|
|
132
|
+
expect(solr_facet_params).to include :"facet.field" => "format"
|
|
133
|
+
expect(solr_facet_params).to include :"f.format.facet.limit" => 21
|
|
134
|
+
expect(solr_facet_params).to include :"f.format.facet.offset" => 0
|
|
135
|
+
expect(solr_facet_params).to include :"rows" => 0
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
describe "get_facet_pagination", :integration => true do
|
|
140
|
+
before do
|
|
141
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
142
|
+
@facet_paginator = subject.get_facet_pagination(@facet_field)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
it 'should return a facet paginator' do
|
|
146
|
+
expect(@facet_paginator).to be_a_kind_of(Blacklight::Solr::FacetPaginator)
|
|
147
|
+
end
|
|
148
|
+
it 'with a limit set' do
|
|
149
|
+
expect(@facet_paginator.limit).not_to be_nil
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# SPECS FOR SEARCH RESULTS FOR QUERY
|
|
154
|
+
describe 'Search Results', :integration => true do
|
|
155
|
+
|
|
156
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
|
157
|
+
describe 'for a sample query returning results' do
|
|
158
|
+
|
|
159
|
+
before do
|
|
160
|
+
(@solr_response, @document_list) = subject.search_results({ q: @all_docs_query }, default_method_chain)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it "should use the configured request handler " do
|
|
164
|
+
allow(blacklight_config).to receive(:default_solr_params).and_return({:qt => 'custom_request_handler'})
|
|
165
|
+
allow(blacklight_solr).to receive(:send_and_receive) do |path, params|
|
|
166
|
+
expect(path).to eq 'select'
|
|
167
|
+
expect(params[:params]['facet.field']).to eq ["format", "{!ex=pub_date_single}pub_date", "subject_topic_facet", "language_facet", "lc_1letter_facet", "subject_geo_facet", "subject_era_facet"]
|
|
168
|
+
expect(params[:params]["facet.query"]).to eq ["pub_date:[#{5.years.ago.year} TO *]", "pub_date:[#{10.years.ago.year} TO *]", "pub_date:[#{25.years.ago.year} TO *]"]
|
|
169
|
+
expect(params[:params]).to include('rows' => 10, 'qt'=>"custom_request_handler", 'q'=>"", "f.subject_topic_facet.facet.limit"=>21, 'sort'=>"score desc, pub_date_sort desc, title_sort asc")
|
|
170
|
+
end.and_return({'response'=>{'docs'=>[]}})
|
|
171
|
+
subject.search_results({ q: @all_docs_query }, default_method_chain)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it 'should have a @response.docs list of the same size as @document_list' do
|
|
175
|
+
expect(@solr_response.docs).to have(@document_list.length).docs
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it 'should have @response.docs list representing same documents as SolrDocuments in @document_list' do
|
|
179
|
+
@solr_response.docs.each_index do |index|
|
|
180
|
+
mash = @solr_response.docs[index]
|
|
181
|
+
solr_document = @document_list[index]
|
|
182
|
+
|
|
183
|
+
expect(Set.new(mash.keys)).to eq Set.new(solr_document.keys)
|
|
184
|
+
|
|
185
|
+
mash.each_key do |key|
|
|
186
|
+
expect(mash[key]).to eq solr_document[key]
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
describe "#get_search_results " do
|
|
193
|
+
it "should be deprecated and return results" do
|
|
194
|
+
expect(Deprecation).to receive(:warn)
|
|
195
|
+
(solr_response, document_list) = subject.get_search_results(q: @all_docs_query)
|
|
196
|
+
result_docs = document_list
|
|
197
|
+
document = result_docs.first
|
|
198
|
+
expect(document.get(blacklight_config.index.title_field)).not_to be_nil
|
|
199
|
+
expect(document.get(blacklight_config.index.display_type_field)).not_to be_nil
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
describe "for a query returning a grouped response" do
|
|
204
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
|
205
|
+
before do
|
|
206
|
+
blacklight_config.default_solr_params[:group] = true
|
|
207
|
+
blacklight_config.default_solr_params[:'group.field'] = 'pub_date_sort'
|
|
208
|
+
(@solr_response, @document_list) = subject.search_results({ q: @all_docs_query }, default_method_chain)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it "should have an empty document list" do
|
|
212
|
+
expect(@document_list).to be_empty
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
it "should return a grouped response" do
|
|
216
|
+
expect(@solr_response).to be_a_kind_of Blacklight::SolrResponse::GroupResponse
|
|
217
|
+
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
describe "for a query returning multiple groups", integration: true do
|
|
222
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
|
223
|
+
|
|
224
|
+
before do
|
|
225
|
+
allow(subject).to receive_messages grouped_key_for_results: 'title_sort'
|
|
226
|
+
blacklight_config.default_solr_params[:group] = true
|
|
227
|
+
blacklight_config.default_solr_params[:'group.field'] = ['pub_date_sort', 'title_sort']
|
|
228
|
+
(@solr_response, @document_list) = subject.search_results({ q: @all_docs_query }, default_method_chain)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
it "should have an empty document list" do
|
|
232
|
+
expect(@document_list).to be_empty
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
it "should return a grouped response" do
|
|
236
|
+
expect(@solr_response).to be_a_kind_of Blacklight::SolrResponse::GroupResponse
|
|
237
|
+
expect(@solr_response.group_field).to eq "title_sort"
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
describe '#query_solr' do
|
|
242
|
+
it 'should have results' do
|
|
243
|
+
expect(Deprecation).to receive(:warn)
|
|
244
|
+
solr_response = subject.query_solr(q: @single_word_query)
|
|
245
|
+
expect(solr_response.docs).to have_at_least(1).result
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
describe 'for All Docs Query, No Facets' do
|
|
251
|
+
it 'should have non-nil values for required doc fields set in initializer' do
|
|
252
|
+
(solr_response, document_list) = subject.search_results({ q: @all_docs_query }, default_method_chain)
|
|
253
|
+
result_docs = document_list
|
|
254
|
+
document = result_docs.first
|
|
255
|
+
expect(document.get(blacklight_config.index.title_field)).not_to be_nil
|
|
256
|
+
expect(document.get(blacklight_config.index.display_type_field)).not_to be_nil
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
describe "Single Word Query with no Facets" do
|
|
263
|
+
it 'should have results' do
|
|
264
|
+
expect(Deprecation).to receive(:warn)
|
|
265
|
+
solr_response = subject.query_solr( q: @single_word_query)
|
|
266
|
+
expect(solr_response.docs).to have_at_least(1).result
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
it 'should have results' do
|
|
270
|
+
(solr_response, document_list) = subject.search_results({ q: @single_word_query }, default_method_chain)
|
|
271
|
+
expect(solr_response.docs).to have(document_list.size).results
|
|
272
|
+
expect(solr_response.docs).to have_at_least(1).result
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
describe "Multiple Words Query with No Facets" do
|
|
277
|
+
it 'should have results' do
|
|
278
|
+
|
|
279
|
+
(solr_response, document_list) = subject.search_results({ q: @mult_word_query }, default_method_chain)
|
|
280
|
+
expect(solr_response.docs).to have(document_list.size).results
|
|
281
|
+
expect(solr_response.docs).to have_at_least(1).result
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
describe "One Facet, No Query" do
|
|
286
|
+
it 'should have results' do
|
|
287
|
+
(solr_response, document_list) = subject.search_results({ f: @single_facet }, default_method_chain)
|
|
288
|
+
expect(solr_response.docs).to have(document_list.size).results
|
|
289
|
+
expect(solr_response.docs).to have_at_least(1).result
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
describe "Mult Facets, No Query" do
|
|
294
|
+
it 'should have results' do
|
|
295
|
+
(solr_response, document_list) = subject.search_results({ f: @multi_facets }, default_method_chain)
|
|
296
|
+
expect(solr_response.docs).to have(document_list.size).results
|
|
297
|
+
expect(solr_response.docs).to have_at_least(1).result
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
describe "Single Word Query with One Facet" do
|
|
302
|
+
it 'should have results' do
|
|
303
|
+
(solr_response, document_list) = subject.search_results({ q: @single_word_query, f: @single_facet }, default_method_chain)
|
|
304
|
+
expect(solr_response.docs).to have(document_list.size).results
|
|
305
|
+
expect(solr_response.docs).to have_at_least(1).result
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
describe "Multiple Words Query with Multiple Facets" do
|
|
310
|
+
it 'should have results' do
|
|
311
|
+
(solr_response, document_list) = subject.search_results({ q: @mult_word_query, f: @multi_facets }, default_method_chain)
|
|
312
|
+
expect(solr_response.docs).to have(document_list.size).results
|
|
313
|
+
expect(solr_response.docs).to have_at_least(1).result
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
describe "for All Docs Query and One Facet" do
|
|
318
|
+
it 'should have results' do
|
|
319
|
+
(solr_response, document_list) = subject.search_results({ q: @all_docs_query, f: @single_facet }, default_method_chain)
|
|
320
|
+
expect(solr_response.docs).to have(document_list.size).results
|
|
321
|
+
expect(solr_response.docs).to have_at_least(1).result
|
|
322
|
+
end
|
|
323
|
+
# TODO: check that number of these results < number of results for all docs query
|
|
324
|
+
# BUT can't: num docs isn't total, it's the num docs in the single SOLR response (e.g. 10)
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
describe "for Query Without Results and No Facet" do
|
|
328
|
+
it 'should have no results and not raise error' do
|
|
329
|
+
(solr_response, document_list) = subject.search_results({ q: @no_docs_query }, default_method_chain)
|
|
330
|
+
expect(document_list).to have(0).results
|
|
331
|
+
expect(solr_response.docs).to have(0).results
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
describe "for Query Without Results and One Facet" do
|
|
336
|
+
it 'should have no results and not raise error' do
|
|
337
|
+
(solr_response, document_list) = subject.search_results({ q: @no_docs_query, f: @single_facet }, default_method_chain)
|
|
338
|
+
expect(document_list).to have(0).results
|
|
339
|
+
expect(solr_response.docs).to have(0).results
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
describe "for All Docs Query and Bad Facet" do
|
|
344
|
+
it 'should have no results and not raise error' do
|
|
345
|
+
(solr_response, document_list) = subject.search_results({ q: @all_docs_query, f: @bad_facet }, default_method_chain)
|
|
346
|
+
expect(document_list).to have(0).results
|
|
347
|
+
expect(solr_response.docs).to have(0).results
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
end # Search Results
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
# SPECS FOR SEARCH RESULTS FOR FACETS
|
|
354
|
+
describe 'Facets in Search Results for All Docs Query', :integration => true do
|
|
355
|
+
|
|
356
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
|
357
|
+
|
|
358
|
+
before do
|
|
359
|
+
(solr_response, document_list) = subject.search_results({ q: @all_docs_query}, default_method_chain)
|
|
360
|
+
@facets = solr_response.facets
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
it 'should have more than one facet' do
|
|
364
|
+
expect(@facets).to have_at_least(1).facet
|
|
365
|
+
end
|
|
366
|
+
it 'should have all facets specified in initializer' do
|
|
367
|
+
fields = blacklight_config.facet_fields.reject { |k,v| v.query || v.pivot }
|
|
368
|
+
expect(@facets.map { |f| f.name }).to match_array fields.map { |k, v| v.field }
|
|
369
|
+
fields.each do |key, field|
|
|
370
|
+
expect(@facets.find {|f| f.name == field.field}).not_to be_nil
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
it 'should have at least one value for each facet' do
|
|
374
|
+
@facets.each do |facet|
|
|
375
|
+
expect(facet.items).to have_at_least(1).hit
|
|
376
|
+
end
|
|
377
|
+
end
|
|
378
|
+
it 'should have multiple values for at least one facet' do
|
|
379
|
+
has_mult_values = false
|
|
380
|
+
@facets.each do |facet|
|
|
381
|
+
if facet.items.size > 1
|
|
382
|
+
has_mult_values = true
|
|
383
|
+
break
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
expect(has_mult_values).to eq true
|
|
387
|
+
end
|
|
388
|
+
it 'should have all value counts > 0' do
|
|
389
|
+
@facets.each do |facet|
|
|
390
|
+
facet.items.each do |facet_vals|
|
|
391
|
+
expect(facet_vals.hits).to be > 0
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
end
|
|
395
|
+
end # facet specs
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
# SPECS FOR SEARCH RESULTS FOR PAGING
|
|
399
|
+
describe 'Paging', :integration => true do
|
|
400
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
|
401
|
+
|
|
402
|
+
it 'should start with first results by default' do
|
|
403
|
+
(solr_response, document_list) = subject.search_results({ q: @all_docs_query }, default_method_chain)
|
|
404
|
+
expect(solr_response.params[:start].to_i).to eq 0
|
|
405
|
+
end
|
|
406
|
+
it 'should have number of results (per page) set in initializer, by default' do
|
|
407
|
+
(solr_response, document_list) = subject.search_results({ q: @all_docs_query }, default_method_chain)
|
|
408
|
+
expect(solr_response.docs).to have(blacklight_config[:default_solr_params][:rows]).items
|
|
409
|
+
expect(document_list).to have(blacklight_config[:default_solr_params][:rows]).items
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
it 'should get number of results per page requested' do
|
|
413
|
+
num_results = 3 # non-default value
|
|
414
|
+
(solr_response1, document_list1) = subject.search_results({ q: @all_docs_query, per_page: num_results }, default_method_chain)
|
|
415
|
+
expect(document_list1).to have(num_results).docs
|
|
416
|
+
expect(solr_response1.docs).to have(num_results).docs
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
it 'should get number of rows requested' do
|
|
420
|
+
num_results = 4 # non-default value
|
|
421
|
+
(solr_response1, document_list1) = subject.search_results({ q: @all_docs_query, rows: num_results }, default_method_chain)
|
|
422
|
+
expect(document_list1).to have(num_results).docs
|
|
423
|
+
expect(solr_response1.docs).to have(num_results).docs
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
it 'should skip appropriate number of results when requested - default per page' do
|
|
427
|
+
page = 3
|
|
428
|
+
(solr_response2, document_list2) = subject.search_results({ q: @all_docs_query, page: page }, default_method_chain)
|
|
429
|
+
expect(solr_response2.params[:start].to_i).to eq blacklight_config[:default_solr_params][:rows] * (page-1)
|
|
430
|
+
end
|
|
431
|
+
it 'should skip appropriate number of results when requested - non-default per page' do
|
|
432
|
+
page = 3
|
|
433
|
+
num_results = 3
|
|
434
|
+
(solr_response2a, document_list2a) = subject.search_results({ q: @all_docs_query, per_page: num_results, page: page }, default_method_chain)
|
|
435
|
+
expect(solr_response2a.params[:start].to_i).to eq num_results * (page-1)
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
it 'should have no results when prompted for page after last result' do
|
|
439
|
+
big = 5000
|
|
440
|
+
(solr_response3, document_list3) = subject.search_results({ q: @all_docs_query, rows: big, page: big }, default_method_chain)
|
|
441
|
+
expect(document_list3).to have(0).docs
|
|
442
|
+
expect(solr_response3.docs).to have(0).docs
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
it 'should show first results when prompted for page before first result' do
|
|
446
|
+
# FIXME: should it show first results, or should it throw an error for view to deal w?
|
|
447
|
+
# Solr throws an error for a negative start value
|
|
448
|
+
(solr_response4, document_list4) = subject.search_results({ q: @all_docs_query, page: '-1' }, default_method_chain)
|
|
449
|
+
expect(solr_response4.params[:start].to_i).to eq 0
|
|
450
|
+
end
|
|
451
|
+
it 'should have results available when asked for more than are in response' do
|
|
452
|
+
big = 5000
|
|
453
|
+
(solr_response5, document_list5) = subject.search_results({ q: @all_docs_query, rows: big, page: 1 }, default_method_chain)
|
|
454
|
+
expect(solr_response5.docs).to have(document_list5.length).docs
|
|
455
|
+
expect(solr_response5.docs).to have_at_least(1).doc
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
end # page specs
|
|
459
|
+
|
|
460
|
+
# SPECS FOR SINGLE DOCUMENT REQUESTS
|
|
461
|
+
describe 'Get Document By Id', :integration => true do
|
|
462
|
+
|
|
463
|
+
describe "#get_solr_response_for_doc_id" do
|
|
464
|
+
let(:doc_id) { '2007020969' }
|
|
465
|
+
it "should be deprecated" do
|
|
466
|
+
expect(Deprecation).to receive(:warn).at_least(1).times
|
|
467
|
+
expect(subject.repository).to receive(:find).with(@doc_id, {}).and_call_original
|
|
468
|
+
subject.get_solr_response_for_doc_id(@doc_id)
|
|
469
|
+
end
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
before do
|
|
473
|
+
@doc_id = '2007020969'
|
|
474
|
+
@bad_id = "redrum"
|
|
475
|
+
@response2, @document = subject.fetch(@doc_id)
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
it "should raise Blacklight::RecordNotFound for an unknown id" do
|
|
479
|
+
expect {
|
|
480
|
+
subject.fetch(@bad_id)
|
|
481
|
+
}.to raise_error(Blacklight::Exceptions::RecordNotFound)
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
it "should use a provided document request handler " do
|
|
485
|
+
allow(blacklight_config).to receive_messages(:document_solr_request_handler => 'document')
|
|
486
|
+
allow(blacklight_solr).to receive(:send_and_receive).with('select', kind_of(Hash)).and_return({'response'=>{'docs'=>[]}})
|
|
487
|
+
expect { subject.fetch(@doc_id)}.to raise_error Blacklight::Exceptions::RecordNotFound
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
it "should use a provided document solr path " do
|
|
491
|
+
allow(blacklight_config).to receive_messages(:document_solr_path => 'get')
|
|
492
|
+
allow(blacklight_solr).to receive(:send_and_receive).with('get', kind_of(Hash)).and_return({'response'=>{'docs'=>[]}})
|
|
493
|
+
expect { subject.fetch(@doc_id)}.to raise_error Blacklight::Exceptions::RecordNotFound
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
it "should have a non-nil result for a known id" do
|
|
497
|
+
expect(@document).not_to be_nil
|
|
498
|
+
end
|
|
499
|
+
it "should have a single document in the response for a known id" do
|
|
500
|
+
expect(@response2.docs.size).to eq 1
|
|
501
|
+
end
|
|
502
|
+
it 'should have the expected value in the id field' do
|
|
503
|
+
expect(@document.id).to eq @doc_id
|
|
504
|
+
end
|
|
505
|
+
it 'should have non-nil values for required fields set in initializer' do
|
|
506
|
+
expect(@document.get(blacklight_config.view_config(:show).display_type_field)).not_to be_nil
|
|
507
|
+
end
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
describe "solr_doc_params" do
|
|
511
|
+
it "should default to using the 'document' requestHandler" do
|
|
512
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
513
|
+
doc_params = subject.solr_doc_params('asdfg')
|
|
514
|
+
expect(doc_params[:qt]).to eq 'document'
|
|
515
|
+
end
|
|
516
|
+
end
|
|
517
|
+
|
|
518
|
+
it "should default to using the id parameter when sending solr queries" do
|
|
519
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
520
|
+
doc_params = subject.solr_doc_params('asdfg')
|
|
521
|
+
expect(doc_params[:id]).to eq 'asdfg'
|
|
522
|
+
end
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
it "should use the document_unique_id_param configuration" do
|
|
526
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
527
|
+
allow(blacklight_config).to receive_messages(document_unique_id_param: :ids)
|
|
528
|
+
doc_params = subject.solr_doc_params('asdfg')
|
|
529
|
+
expect(doc_params[:ids]).to eq 'asdfg'
|
|
530
|
+
end
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
describe "blacklight config's default_document_solr_parameters" do
|
|
534
|
+
it "should use parameters from the controller's default_document_solr_parameters" do
|
|
535
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
536
|
+
blacklight_config.default_document_solr_params = { :qt => 'my_custom_handler', :asdf => '1234' }
|
|
537
|
+
doc_params = subject.solr_doc_params('asdfg')
|
|
538
|
+
expect(doc_params[:qt]).to eq 'my_custom_handler'
|
|
539
|
+
expect(doc_params[:asdf]).to eq '1234'
|
|
540
|
+
end
|
|
541
|
+
end
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
describe "Get Document by custom unique id" do
|
|
547
|
+
=begin
|
|
548
|
+
# Can't test this properly without updating the "document" request handler in solr
|
|
549
|
+
it "should respect the configuration-supplied unique id" do
|
|
550
|
+
allow(SolrDocument).to receive(:unique_key).and_return("title_display")
|
|
551
|
+
@response, @document = @solr_helper.fetch('"Strong Medicine speaks"')
|
|
552
|
+
@document.id).to eq '"Strong Medicine speaks"'
|
|
553
|
+
@document.get(:id)).to eq 2007020969
|
|
554
|
+
end
|
|
555
|
+
=end
|
|
556
|
+
it "should respect the configuration-supplied unique id" do
|
|
557
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
558
|
+
doc_params = subject.solr_doc_params('"Strong Medicine speaks"')
|
|
559
|
+
expect(doc_params[:id]).to eq '"Strong Medicine speaks"'
|
|
560
|
+
end
|
|
561
|
+
end
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
# SPECS FOR SINGLE DOCUMENT VIA SEARCH
|
|
567
|
+
describe "Get Document Via Search", :integration => true do
|
|
568
|
+
before do
|
|
569
|
+
@doc_row = 3
|
|
570
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
571
|
+
@doc = subject.get_single_doc_via_search(@doc_row, :q => @all_docs_query)
|
|
572
|
+
end
|
|
573
|
+
end
|
|
574
|
+
=begin
|
|
575
|
+
# can't test these here, because the method only returns the document
|
|
576
|
+
it "should get a single document" do
|
|
577
|
+
response.docs.size).to eq 1
|
|
578
|
+
end
|
|
579
|
+
|
|
580
|
+
doc2 = get_single_doc_via_search(@all_docs_query, nil, @doc_row, @multi_facets)
|
|
581
|
+
it "should limit search result by facets when supplied" do
|
|
582
|
+
response2expect(.docs.numFound).to_be < response.docs.numFound
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
it "should not have facets in the response" do
|
|
586
|
+
response.facets.size).to eq 0
|
|
587
|
+
end
|
|
588
|
+
=end
|
|
589
|
+
|
|
590
|
+
it 'should have a doc id field' do
|
|
591
|
+
expect(@doc[:id]).not_to be_nil
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
it 'should have non-nil values for required fields set in initializer' do
|
|
595
|
+
expect(@doc[blacklight_config.view_config(:show).display_type_field]).not_to be_nil
|
|
596
|
+
end
|
|
597
|
+
|
|
598
|
+
it "should limit search result by facets when supplied" do
|
|
599
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
600
|
+
doc2 = subject.get_single_doc_via_search(@doc_row , :q => @all_docs_query, :f => @multi_facets)
|
|
601
|
+
expect(doc2[:id]).not_to be_nil
|
|
602
|
+
end
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
end
|
|
606
|
+
|
|
607
|
+
# SPECS FOR SPELLING SUGGESTIONS VIA SEARCH
|
|
608
|
+
describe "Searches should return spelling suggestions", :integration => true do
|
|
609
|
+
it 'search results for just-poor-enough-query term should have (multiple) spelling suggestions' do
|
|
610
|
+
(solr_response, document_list) = subject.search_results({ q: 'boo' }, default_method_chain)
|
|
611
|
+
expect(solr_response.spelling.words).to include('bon')
|
|
612
|
+
expect(solr_response.spelling.words).to include('bod') #for multiple suggestions
|
|
613
|
+
end
|
|
614
|
+
|
|
615
|
+
it 'search results for just-poor-enough-query term should have multiple spelling suggestions' do
|
|
616
|
+
(solr_response, document_list) = subject.search_results({ q: 'politica' }, default_method_chain)
|
|
617
|
+
expect(solr_response.spelling.words).to include('policy') # less freq
|
|
618
|
+
expect(solr_response.spelling.words).to include('politics') # more freq
|
|
619
|
+
expect(solr_response.spelling.words).to include('political') # more freq
|
|
620
|
+
=begin
|
|
621
|
+
# when we can have multiple suggestions
|
|
622
|
+
expect(solr_response.spelling.words).to_not include('policy') # less freq
|
|
623
|
+
solr_response.spelling.words).to include('politics') # more freq
|
|
624
|
+
solr_response.spelling.words).to include('political') # more freq
|
|
625
|
+
=end
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
it "title search results for just-poor-enough query term should have spelling suggestions" do
|
|
629
|
+
(solr_response, document_list) = subject.search_results({ q: 'yehudiyam', qt: 'search', :"spellcheck.dictionary" => "title" }, default_method_chain)
|
|
630
|
+
expect(solr_response.spelling.words).to include('yehudiyim')
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
it "author search results for just-poor-enough-query term should have spelling suggestions" do
|
|
634
|
+
(solr_response, document_list) = subject.search_results({ q: 'shirma', qt: 'search', :"spellcheck.dictionary" => "author" }, default_method_chain)
|
|
635
|
+
expect(solr_response.spelling.words).to include('sharma')
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
it "subject search results for just-poor-enough-query term should have spelling suggestions" do
|
|
639
|
+
(solr_response, document_list) = subject.search_results({ q: 'wome', qt: 'search', :"spellcheck.dictionary" => "subject" }, default_method_chain)
|
|
640
|
+
expect(solr_response.spelling.words).to include('women')
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
it 'search results for multiple terms query with just-poor-enough-terms should have spelling suggestions for each term' do
|
|
644
|
+
skip
|
|
645
|
+
# get_spelling_suggestion("histo politica").should_not be_nil
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
end
|
|
649
|
+
|
|
650
|
+
describe "facet_limit_for" do
|
|
651
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
|
652
|
+
|
|
653
|
+
it "should return specified value for facet_field specified" do
|
|
654
|
+
expect(subject.facet_limit_for("subject_topic_facet")).to eq blacklight_config.facet_fields["subject_topic_facet"].limit
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
it "facet_limit_hash should return hash with key being facet_field and value being configured limit" do
|
|
658
|
+
# facet_limit_hash has been removed from solrhelper in refactor. should it go back?
|
|
659
|
+
skip "facet_limit_hash has been removed from solrhelper in refactor. should it go back?"
|
|
660
|
+
expect(subject.facet_limit_hash).to eq blacklight_config[:facet][:limits]
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
it "should handle no facet_limits in config" do
|
|
664
|
+
blacklight_config.facet_fields = {}
|
|
665
|
+
expect(subject.facet_limit_for("subject_topic_facet")).to be_nil
|
|
666
|
+
end
|
|
667
|
+
|
|
668
|
+
describe "for 'true' configured values" do
|
|
669
|
+
let(:blacklight_config) do
|
|
670
|
+
config = Blacklight::Configuration.new
|
|
671
|
+
config.add_facet_field "language_facet", limit: true
|
|
672
|
+
config
|
|
673
|
+
end
|
|
674
|
+
it "should return nil if no @response available" do
|
|
675
|
+
expect(subject.facet_limit_for("some_unknown_field")).to be_nil
|
|
676
|
+
end
|
|
677
|
+
it "should get from @response facet.limit if available" do
|
|
678
|
+
@response = double()
|
|
679
|
+
allow(@response).to receive(:facet_by_field_name).with("language_facet").and_return(double(limit: nil))
|
|
680
|
+
subject.instance_variable_set(:@response, @response)
|
|
681
|
+
blacklight_config.facet_fields['language_facet'].limit = 10
|
|
682
|
+
expect(subject.facet_limit_for("language_facet")).to eq 10
|
|
683
|
+
end
|
|
684
|
+
it "should get the limit from the facet field in @response" do
|
|
685
|
+
@response = double()
|
|
686
|
+
allow(@response).to receive(:facet_by_field_name).with("language_facet").and_return(double(limit: 16))
|
|
687
|
+
subject.instance_variable_set(:@response, @response)
|
|
688
|
+
expect(subject.facet_limit_for("language_facet")).to eq 15
|
|
689
|
+
end
|
|
690
|
+
it "should default to 10" do
|
|
691
|
+
expect(subject.facet_limit_for("language_facet")).to eq 10
|
|
692
|
+
end
|
|
693
|
+
end
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
describe "#get_solr_response_for_field_values" do
|
|
697
|
+
before do
|
|
698
|
+
@mock_response = double()
|
|
699
|
+
allow(@mock_response).to receive_messages(documents: [])
|
|
700
|
+
end
|
|
701
|
+
it "should contruct a solr query based on the field and value pair" do
|
|
702
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
703
|
+
allow(subject.repository).to receive(:send_and_receive).with('select', hash_including("q" => "{!lucene}field_name:(value)")).and_return(@mock_response)
|
|
704
|
+
subject.get_solr_response_for_field_values('field_name', 'value')
|
|
705
|
+
end
|
|
706
|
+
end
|
|
707
|
+
|
|
708
|
+
it "should OR multiple values together" do
|
|
709
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
710
|
+
allow(subject.repository).to receive(:send_and_receive).with('select', hash_including("q" => "{!lucene}field_name:(a OR b)")).and_return(@mock_response)
|
|
711
|
+
subject.get_solr_response_for_field_values('field_name', ['a', 'b'])
|
|
712
|
+
end
|
|
713
|
+
end
|
|
714
|
+
|
|
715
|
+
it "should escape crazy identifiers" do
|
|
716
|
+
Deprecation.silence(Blacklight::SearchHelper) do
|
|
717
|
+
allow(subject.repository).to receive(:send_and_receive).with('select', hash_including("q" => "{!lucene}field_name:(\"h://\\\"\\\'\")")).and_return(@mock_response)
|
|
718
|
+
subject.get_solr_response_for_field_values('field_name', 'h://"\'')
|
|
719
|
+
end
|
|
720
|
+
end
|
|
721
|
+
end
|
|
722
|
+
|
|
723
|
+
# TODO: more complex queries! phrases, offset into search results, non-latin, boosting(?)
|
|
724
|
+
# search within query building (?)
|
|
725
|
+
# search + facets (search done first; facet selected first, both selected)
|
|
726
|
+
|
|
727
|
+
# TODO: maybe eventually check other types of solr requests
|
|
728
|
+
# more like this
|
|
729
|
+
# nearby on shelf
|
|
730
|
+
it "should raise a Blacklight exception if RSolr can't connect to the Solr instance" do
|
|
731
|
+
allow(blacklight_solr).to receive(:send_and_receive).and_raise(Errno::ECONNREFUSED)
|
|
732
|
+
expect(Deprecation).to receive(:warn)
|
|
733
|
+
expect { subject.query_solr }.to raise_exception(/Unable to connect to Solr instance/)
|
|
734
|
+
end
|
|
735
|
+
|
|
736
|
+
describe "grouped_key_for_results" do
|
|
737
|
+
it "should pull the grouped key out of the config" do
|
|
738
|
+
blacklight_config.index.group = 'xyz'
|
|
739
|
+
expect(subject.grouped_key_for_results).to eq('xyz')
|
|
740
|
+
end
|
|
741
|
+
end
|
|
742
|
+
|
|
743
|
+
describe "#get_previous_and_next_documents_for_search" do
|
|
744
|
+
let(:pre_query) { SearchHelperTestClass.new blacklight_config, blacklight_solr }
|
|
745
|
+
before do
|
|
746
|
+
@full_response, @all_docs = pre_query.search_results({ q: '', per_page: '100' }, default_method_chain)
|
|
747
|
+
end
|
|
748
|
+
|
|
749
|
+
it "should return the previous and next documents for a search" do
|
|
750
|
+
response, docs = subject.get_previous_and_next_documents_for_search(4, :q => '')
|
|
751
|
+
|
|
752
|
+
expect(docs.first.id).to eq @all_docs[3].id
|
|
753
|
+
expect(docs.last.id).to eq @all_docs[5].id
|
|
754
|
+
end
|
|
755
|
+
|
|
756
|
+
it "should return only the next document if the counter is 0" do
|
|
757
|
+
response, docs = subject.get_previous_and_next_documents_for_search(0, :q => '')
|
|
758
|
+
|
|
759
|
+
expect(docs.first).to be_nil
|
|
760
|
+
expect(docs.last.id).to eq @all_docs[1].id
|
|
761
|
+
end
|
|
762
|
+
|
|
763
|
+
it "should return only the previous document if the counter is the total number of documents" do
|
|
764
|
+
response, docs = subject.get_previous_and_next_documents_for_search(@full_response.total - 1, :q => '')
|
|
765
|
+
expect(docs.first.id).to eq @all_docs.slice(-2).id
|
|
766
|
+
expect(docs.last).to be_nil
|
|
767
|
+
end
|
|
768
|
+
|
|
769
|
+
it "should return an array of nil values if there is only one result" do
|
|
770
|
+
response, docs = subject.get_previous_and_next_documents_for_search(0, :q => 'id:2007020969')
|
|
771
|
+
expect(docs.last).to be_nil
|
|
772
|
+
expect(docs.first).to be_nil
|
|
773
|
+
end
|
|
774
|
+
end
|
|
775
|
+
end
|