blacklight 3.1.2 → 3.2.0pre1
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.
- data/.gitignore +5 -2
- data/README.md +7 -2
- data/VERSION +1 -1
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/javascripts/blacklight/blacklight.js +23 -1
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +369 -0
- data/app/assets/stylesheets/blacklight/_facets.css.scss +117 -0
- data/app/assets/stylesheets/blacklight/_folder.css.scss +38 -0
- data/app/assets/stylesheets/blacklight/_formatting.css.scss +164 -0
- data/app/assets/stylesheets/blacklight/_header.css.scss +36 -0
- data/app/assets/stylesheets/blacklight/_layout.css.scss +79 -0
- data/app/assets/stylesheets/blacklight/_print.css.scss +54 -0
- data/app/assets/stylesheets/blacklight/_search_history.css.scss +44 -0
- data/app/assets/stylesheets/blacklight/_susy_framework.css.scss +228 -0
- data/app/assets/stylesheets/blacklight/blacklight.css.scss +27 -0
- data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +48 -0
- data/app/controllers/bookmarks_controller.rb +2 -1
- data/app/controllers/folder_controller.rb +4 -0
- data/app/controllers/saved_searches_controller.rb +4 -0
- data/app/controllers/search_history_controller.rb +4 -0
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +64 -104
- data/app/helpers/blacklight/catalog_helper_behavior.rb +4 -4
- data/app/helpers/blacklight/facets_helper_behavior.rb +52 -5
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +14 -59
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +56 -0
- data/app/helpers/search_history_constraints_helper.rb +3 -0
- data/app/models/record_mailer.rb +1 -2
- data/app/views/_flash_msg.html.erb +4 -5
- data/app/views/_user_util_links.html.erb +3 -1
- data/app/views/bookmarks/index.html.erb +2 -2
- data/app/views/catalog/_bookmark_control.html.erb +6 -6
- data/app/views/catalog/_facet_layout.html.erb +4 -0
- data/app/views/catalog/_facet_limit.html.erb +20 -33
- data/app/views/catalog/_facets.html.erb +1 -5
- data/app/views/catalog/_folder_control.html.erb +5 -5
- data/app/views/catalog/_index_default.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +4 -3
- data/app/views/catalog/_show_default.html.erb +1 -1
- data/app/views/catalog/_show_tools.html.erb +6 -6
- data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
- data/app/views/catalog/index.atom.builder +2 -2
- data/app/views/catalog/index.rss.builder +1 -1
- data/app/views/catalog/opensearch.xml.builder +10 -0
- data/app/views/catalog/show.html.erb +1 -1
- data/app/views/folder/_tools.html.erb +4 -4
- data/app/views/layouts/blacklight.html.erb +25 -37
- data/app/views/record_mailer/email_record.text.erb +1 -1
- data/app/views/record_mailer/sms_record.text.erb +2 -2
- data/app/views/search_history/index.html.erb +1 -1
- data/blacklight.gemspec +11 -9
- data/lib/{generators/blacklight/templates/SolrMarc.jar → SolrMarc.jar} +0 -0
- data/lib/blacklight.rb +5 -3
- data/lib/blacklight/catalog.rb +3 -4
- data/lib/blacklight/configurable.rb +54 -39
- data/lib/blacklight/configuration.rb +126 -0
- data/lib/blacklight/configuration/fields.rb +142 -0
- data/lib/blacklight/configuration/search_field.rb +12 -0
- data/lib/blacklight/configuration/solr_field.rb +12 -0
- data/lib/blacklight/configuration/sort_field.rb +17 -0
- data/lib/blacklight/controller.rb +16 -14
- data/lib/blacklight/engine.rb +1 -1
- data/lib/blacklight/global_configurable.rb +46 -0
- data/lib/blacklight/search_fields.rb +21 -54
- data/lib/blacklight/solr/document.rb +13 -3
- data/lib/blacklight/solr_helper.rb +88 -52
- data/lib/blacklight/utils.rb +18 -0
- data/lib/generators/blacklight/assets_generator.rb +14 -20
- data/lib/generators/blacklight/blacklight_generator.rb +14 -6
- data/lib/generators/blacklight/jetty_generator.rb +1 -1
- data/lib/generators/blacklight/templates/assets/standard.css.scss +51 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +148 -0
- data/lib/generators/blacklight/templates/config/blacklight_config.rb +2 -239
- data/lib/generators/blacklight/templates/config/sass.rb +5 -0
- data/lib/generators/blacklight/templates/solr_conf/schema.xml +514 -164
- data/lib/generators/blacklight/templates/solr_conf/solrconfig.xml +1591 -323
- data/lib/generators/blacklight/templates/solr_document.rb +2 -0
- data/lib/railties/all_tests.rake +36 -3
- data/lib/railties/blacklight_cucumber.rake +6 -4
- data/lib/railties/blacklight_rspec.rake +5 -4
- data/test_support/bin/run-tests.sh +2 -13
- data/test_support/bin/test.sh +30 -23
- data/test_support/features/did_you_mean.feature +14 -13
- data/test_support/features/step_definitions/saved_searches_steps.rb +1 -1
- data/test_support/features/step_definitions/search_steps.rb +4 -4
- data/test_support/spec/controllers/application_controller_spec.rb +3 -13
- data/test_support/spec/controllers/catalog_controller_spec.rb +102 -24
- data/test_support/spec/controllers/folder_controller_spec.rb +7 -1
- data/test_support/spec/helpers/blacklight_helper_spec.rb +45 -34
- data/test_support/spec/helpers/facets_helper_spec.rb +68 -0
- data/test_support/spec/helpers/html_head_helper_spec.rb +37 -0
- data/test_support/spec/helpers/{render_constraints_helper_spec.rb → search_history_constraints_helper_spec.rb} +26 -7
- data/test_support/spec/lib/blacklight_configurable_spec.rb +92 -0
- data/test_support/spec/lib/blacklight_configuration_spec.rb +295 -0
- data/test_support/spec/lib/{configurable_spec.rb → global_configurable_spec.rb} +2 -2
- data/test_support/spec/lib/search_fields_spec.rb +26 -29
- data/test_support/spec/{helpers → lib}/solr_helper_spec.rb +268 -287
- data/test_support/spec/lib/tasks/solr_marc_task_spec.rb +1 -1
- data/test_support/spec/lib/utils_spec.rb +58 -0
- data/test_support/spec/models/solr_docment_spec.rb +4 -8
- data/test_support/spec/views/catalog/_facets.html.erb_spec.rb +27 -170
- data/test_support/spec/views/catalog/_index_default.erb_spec.rb +38 -20
- data/test_support/spec/views/catalog/_show_default.erb_spec.rb +38 -19
- data/test_support/spec/views/catalog/index.atom.builder_spec.rb +19 -1
- metadata +148 -145
- data/app/assets/stylesheets/blacklight/blacklight.css +0 -493
- data/app/assets/stylesheets/yui.css +0 -31
- data/app/views/catalog/opensearch.xml.erb +0 -11
- data/doc/Atom-Responses.md +0 -90
- data/doc/CUSTOMIZING.md +0 -121
- data/doc/Extending-blacklight-with-the-document-extension-framework.md +0 -1
- data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -131
- data/doc/Features.md +0 -147
- data/doc/Integration-with-Rails-Footnotes.md +0 -20
- data/doc/Pagination.md +0 -38
- data/doc/Quickstart.md +0 -97
- data/doc/Upgrading-Guide.md +0 -98
- data/doc/User-Authentication.md +0 -54
- data/doc/Using-a-custom-solr-uniquekey-field.md +0 -36
- data/lib/blacklight/comma_link_renderer.rb +0 -28
- data/lib/railties/jetty_solr_server.rb +0 -108
- data/test_support/spec/views/catalog/show.html.erb_spec.rb +0 -101
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
|
|
4
|
-
describe Blacklight::
|
|
4
|
+
describe Blacklight::GlobalConfigurable do
|
|
5
5
|
|
|
6
6
|
class TestConfig
|
|
7
|
-
extend Blacklight::
|
|
7
|
+
extend Blacklight::GlobalConfigurable
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
before(:each) do
|
|
@@ -5,46 +5,45 @@ describe Blacklight::SearchFields do
|
|
|
5
5
|
|
|
6
6
|
class MockConfig
|
|
7
7
|
include Blacklight::SearchFields
|
|
8
|
+
end
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def config
|
|
12
|
-
@config ||= {:search_fields => [ {:display_label => 'All Fields', :key => "all_fields"},
|
|
10
|
+
before(:all) do
|
|
11
|
+
@config = Blacklight::Configuration.from_legacy_configuration({:search_fields => [ {:label => 'All Fields', :key => "all_fields"},
|
|
13
12
|
{:key => 'title', :qt => 'title_search'},
|
|
14
13
|
{:key => 'author', :qt => 'author_search'},
|
|
15
14
|
{:key => 'subject', :qt=> 'subject_search'},
|
|
16
15
|
['Legacy Config', 'legacy_qt'],
|
|
17
16
|
{:key => "no_display", :qt=>"something", :include_in_simple_select => false}
|
|
18
17
|
],
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
|
|
18
|
+
:default_solr_params => { :qt => "search" }
|
|
19
|
+
})
|
|
23
20
|
end
|
|
24
21
|
|
|
25
|
-
before(:
|
|
22
|
+
before(:each) do
|
|
26
23
|
@search_field_obj = MockConfig.new
|
|
24
|
+
@search_field_obj.stub!(:blacklight_config).and_return(@config)
|
|
27
25
|
end
|
|
28
26
|
|
|
29
27
|
it 'should convert legacy Array config to Hash properly' do
|
|
30
28
|
hash = @search_field_obj.search_field_def_for_key('legacy_qt')
|
|
31
29
|
|
|
32
|
-
hash.should be_kind_of(
|
|
33
|
-
hash
|
|
34
|
-
hash
|
|
30
|
+
hash.should be_kind_of(Blacklight::Configuration::SearchField)
|
|
31
|
+
hash.key.should == hash.qt
|
|
32
|
+
hash.label.should == 'Legacy Config'
|
|
35
33
|
end
|
|
36
34
|
|
|
37
|
-
it "should return search field list with calculated :
|
|
35
|
+
it "should return search field list with calculated :label when needed" do
|
|
38
36
|
@search_field_obj.search_field_list.each do |hash|
|
|
39
|
-
hash
|
|
37
|
+
hash.label.should_not be_blank
|
|
40
38
|
end
|
|
41
39
|
end
|
|
42
40
|
|
|
43
41
|
it "should fill in default qt where needed" do
|
|
44
|
-
@search_field_obj.search_field_def_for_key("all_fields")
|
|
42
|
+
@search_field_obj.search_field_def_for_key("all_fields").qt == @config.default_solr_params[:qt]
|
|
45
43
|
end
|
|
46
44
|
|
|
47
45
|
it "should return proper options_for_select arguments" do
|
|
46
|
+
|
|
48
47
|
select_arguments = @search_field_obj.search_field_options_for_select
|
|
49
48
|
|
|
50
49
|
select_arguments.each_index do |index|
|
|
@@ -52,8 +51,8 @@ describe Blacklight::SearchFields do
|
|
|
52
51
|
config_hash = @search_field_obj.search_field_list[index]
|
|
53
52
|
|
|
54
53
|
argument.length.should == 2
|
|
55
|
-
argument[0].should == config_hash
|
|
56
|
-
argument[1].should == config_hash
|
|
54
|
+
argument[0].should == config_hash.label
|
|
55
|
+
argument[1].should == config_hash.key
|
|
57
56
|
end
|
|
58
57
|
end
|
|
59
58
|
|
|
@@ -66,10 +65,10 @@ describe Blacklight::SearchFields do
|
|
|
66
65
|
|
|
67
66
|
|
|
68
67
|
it "should lookup field definitions by key" do
|
|
69
|
-
@search_field_obj.search_field_def_for_key("title")
|
|
68
|
+
@search_field_obj.search_field_def_for_key("title").key.should == "title"
|
|
70
69
|
end
|
|
71
70
|
|
|
72
|
-
it "should find
|
|
71
|
+
it "should find label by key" do
|
|
73
72
|
@search_field_obj.label_for_search_field("title").should == "Title"
|
|
74
73
|
end
|
|
75
74
|
|
|
@@ -80,26 +79,24 @@ describe Blacklight::SearchFields do
|
|
|
80
79
|
describe "for unspecified :key" do
|
|
81
80
|
before do
|
|
82
81
|
@bad_config = MockConfig.new
|
|
83
|
-
@bad_config.config[:search_fields] = [
|
|
84
|
-
{:display_label => 'All Fields', :qt => "all_fields"},
|
|
85
|
-
{:key => 'title', :qt => 'title_search'}
|
|
86
|
-
]
|
|
87
82
|
end
|
|
88
83
|
it "should raise exception on #search_field_list" do
|
|
89
|
-
lambda {@bad_config.
|
|
84
|
+
lambda { @bad_config.stub(:blacklight_config).and_return(Blacklight::Configuration.from_legacy_configuration({:search_fields => [
|
|
85
|
+
{:label => 'All Fields', :qt => "all_fields"},
|
|
86
|
+
{:key => 'title', :qt => 'title_search'}
|
|
87
|
+
]})) }.should raise_error
|
|
90
88
|
end
|
|
91
89
|
end
|
|
92
90
|
|
|
93
91
|
describe "for duplicate keys" do
|
|
94
92
|
before do
|
|
95
93
|
@bad_config = MockConfig.new
|
|
96
|
-
@bad_config.config[:search_fields] = [
|
|
97
|
-
{:display_label => 'All Fields', :key => "my_key"},
|
|
98
|
-
{:key => 'title', :key => 'my_key'}
|
|
99
|
-
]
|
|
100
94
|
end
|
|
101
95
|
it "should raise on #search_field_list" do
|
|
102
|
-
lambda {@bad_config.
|
|
96
|
+
lambda { @bad_config.stub(:blacklight_config).and_return(Blacklight::Configuration.from_legacy_configuration({:search_fields => [
|
|
97
|
+
{:label => 'All Fields', :qt => "my_key"},
|
|
98
|
+
{:key => 'title', :qt => 'my_key'}
|
|
99
|
+
]})) }.should raise_error
|
|
103
100
|
end
|
|
104
101
|
end
|
|
105
102
|
|
|
@@ -2,22 +2,7 @@
|
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
require 'marc'
|
|
4
4
|
|
|
5
|
-
# Because SolrHelper is a controller layer mixin,
|
|
6
|
-
# it depends on the methods provided by AtionController::Base
|
|
7
|
-
# currently, the only method that is used is #params
|
|
8
|
-
class MockSolrHelperContainer
|
|
9
5
|
|
|
10
|
-
include Blacklight::SolrHelper
|
|
11
|
-
attr_accessor :params
|
|
12
|
-
attr_accessor :response
|
|
13
|
-
|
|
14
|
-
# SolrHelper expects a method called #params,
|
|
15
|
-
# within the class that's mixing it in
|
|
16
|
-
def params
|
|
17
|
-
@params ||= {}
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
end
|
|
21
6
|
|
|
22
7
|
|
|
23
8
|
=begin
|
|
@@ -31,11 +16,23 @@ end
|
|
|
31
16
|
=end
|
|
32
17
|
describe 'Blacklight::SolrHelper' do
|
|
33
18
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
# SolrHelper is a controller layer mixin, which depends
|
|
20
|
+
# on being mixed into a class which has #params (from Rails)
|
|
21
|
+
# and #blacklight_config
|
|
22
|
+
def params
|
|
23
|
+
{}
|
|
37
24
|
end
|
|
38
25
|
|
|
26
|
+
def blacklight_config
|
|
27
|
+
@config ||= CatalogController.blacklight_config
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def blacklight_config=(config)
|
|
31
|
+
@config = config
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
include Blacklight::SolrHelper
|
|
35
|
+
|
|
39
36
|
before(:each) do
|
|
40
37
|
@all_docs_query = ''
|
|
41
38
|
@no_docs_query = 'zzzzzzzzzzzz'
|
|
@@ -45,62 +42,46 @@ describe 'Blacklight::SolrHelper' do
|
|
|
45
42
|
@single_facet = {:format=>'Book'}
|
|
46
43
|
@multi_facets = {:format=>'Book', :language_facet=>'Tibetan'}
|
|
47
44
|
@bad_facet = {:format=>'666'}
|
|
48
|
-
@subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"
|
|
45
|
+
@subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"rows"=>"10", :"q"=>"wome"}
|
|
49
46
|
end
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
describe "blacklight.rb" do
|
|
53
|
-
describe "solr.yml and/or initializers" do
|
|
54
|
-
|
|
55
|
-
it "should contain a solr_url" do
|
|
56
|
-
Blacklight.solr_config[:url].should_not == nil
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "should contain some display fields" do
|
|
60
|
-
Blacklight.config[:show].should_not == nil
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
end
|
|
64
|
-
end
|
|
48
|
+
|
|
65
49
|
|
|
66
50
|
# SPECS for actual search parameter generation
|
|
67
51
|
describe "solr_search_params" do
|
|
68
52
|
it "allows customization of solr_search_params_logic" do
|
|
69
53
|
# Normally you'd include a new module into (eg) your CatalogController
|
|
70
|
-
# but a sub-class defininig it directly is simpler for test.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
end
|
|
54
|
+
# but a sub-class defininig it directly is simpler for test.
|
|
55
|
+
def add_foo_to_solr_params(solr_params, user_params)
|
|
56
|
+
solr_params[:foo] = "TESTING"
|
|
57
|
+
end
|
|
58
|
+
|
|
76
59
|
|
|
77
|
-
|
|
78
|
-
|
|
60
|
+
self.solr_search_params_logic += [:add_foo_to_solr_params]
|
|
79
61
|
|
|
80
|
-
obj = CustomizableHelper.new
|
|
81
|
-
params = obj.solr_search_params
|
|
82
62
|
|
|
83
|
-
|
|
63
|
+
self.solr_search_params[:foo].should == "TESTING"
|
|
84
64
|
end
|
|
85
65
|
|
|
86
66
|
|
|
87
67
|
describe 'for an entirely empty search' do
|
|
68
|
+
def params
|
|
69
|
+
{}
|
|
70
|
+
end
|
|
88
71
|
before do
|
|
89
|
-
@produced_params =
|
|
72
|
+
@produced_params = self.solr_search_params
|
|
90
73
|
end
|
|
91
74
|
it 'should not have a q param' do
|
|
92
75
|
@produced_params[:q].should be_nil
|
|
93
76
|
@produced_params["spellcheck.q"].should be_nil
|
|
94
77
|
end
|
|
95
|
-
it 'should have default
|
|
96
|
-
@produced_params[:
|
|
78
|
+
it 'should have default rows' do
|
|
79
|
+
@produced_params[:rows].should == 10
|
|
97
80
|
end
|
|
98
81
|
it 'should have default facet fields' do
|
|
99
|
-
@produced_params[:"facet.field"].should ==
|
|
100
|
-
end
|
|
101
|
-
it 'should not use the exact facet array from config defaults' do
|
|
102
|
-
@produced_params[:"facet.field"].should_not be_equal(Blacklight.config[:facet][:field_names])
|
|
82
|
+
@produced_params[:"facet.field"].should == blacklight_config[:default_solr_params][:"facet.field"]
|
|
103
83
|
end
|
|
84
|
+
|
|
104
85
|
it "should have default qt" do
|
|
105
86
|
@produced_params[:qt].should == "search"
|
|
106
87
|
end
|
|
@@ -111,21 +92,17 @@ describe 'Blacklight::SolrHelper' do
|
|
|
111
92
|
end
|
|
112
93
|
|
|
113
94
|
|
|
114
|
-
describe "for an empty string search" do
|
|
115
|
-
it "should return empty string q in solr parameters" do
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
95
|
+
describe "for an empty string search" do
|
|
96
|
+
it "should return empty string q in solr parameters" do
|
|
97
|
+
solr_params = solr_search_params(:q => "")
|
|
98
|
+
solr_params[:q].should == ""
|
|
99
|
+
solr_params["spellcheck.q"].should == ""
|
|
119
100
|
end
|
|
120
101
|
end
|
|
121
102
|
|
|
122
|
-
describe "for request params also passed in as argument" do
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
params = @req_params
|
|
126
|
-
end
|
|
127
|
-
it "should only have one 'q' key, as symbol" do
|
|
128
|
-
solr_params = @solr_helper.solr_search_params( @req_params )
|
|
103
|
+
describe "for request params also passed in as argument" do
|
|
104
|
+
it "should only have one 'q' key, as symbol" do
|
|
105
|
+
solr_params = solr_search_params( :q => "some query" )
|
|
129
106
|
solr_params.keys.should include(:q)
|
|
130
107
|
solr_params.keys.should_not include("q")
|
|
131
108
|
end
|
|
@@ -135,27 +112,27 @@ describe 'Blacklight::SolrHelper' do
|
|
|
135
112
|
describe "for one facet, no query" do
|
|
136
113
|
it "should have proper solr parameters" do
|
|
137
114
|
|
|
138
|
-
|
|
115
|
+
solr_params = solr_search_params(:f => @single_facet)
|
|
139
116
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
117
|
+
solr_params[:q].should be_blank
|
|
118
|
+
solr_params["spellcheck.q"].should be_blank
|
|
119
|
+
solr_params[:"facet.field"].should == blacklight_config[:default_solr_params][:"facet.field"]
|
|
143
120
|
|
|
144
121
|
@single_facet.each_value do |value|
|
|
145
|
-
|
|
122
|
+
solr_params[:fq].should include("{!raw f=#{@single_facet.keys[0]}}#{value}")
|
|
146
123
|
end
|
|
147
124
|
end
|
|
148
125
|
end
|
|
149
126
|
|
|
150
127
|
describe "with Multi Facets, No Query" do
|
|
151
128
|
it 'should have fq set properly' do
|
|
152
|
-
|
|
129
|
+
solr_params = solr_search_params(:f => @multi_facets)
|
|
153
130
|
|
|
154
131
|
@multi_facets.each_pair do |facet_field, value_list|
|
|
155
132
|
value_list ||= []
|
|
156
133
|
value_list = [value_list] unless value_list.respond_to? :each
|
|
157
134
|
value_list.each do |value|
|
|
158
|
-
|
|
135
|
+
solr_params[:fq].should include("{!raw f=#{facet_field}}#{value}" )
|
|
159
136
|
end
|
|
160
137
|
end
|
|
161
138
|
|
|
@@ -164,22 +141,48 @@ describe 'Blacklight::SolrHelper' do
|
|
|
164
141
|
|
|
165
142
|
describe "with Multi Facets, Multi Word Query" do
|
|
166
143
|
it 'should have fq and q set properly' do
|
|
167
|
-
|
|
144
|
+
solr_params = solr_search_params(:q => @mult_word_query, :f => @multi_facets)
|
|
168
145
|
|
|
169
146
|
@multi_facets.each_pair do |facet_field, value_list|
|
|
170
147
|
value_list ||= []
|
|
171
148
|
value_list = [value_list] unless value_list.respond_to? :each
|
|
172
149
|
value_list.each do |value|
|
|
173
|
-
|
|
150
|
+
solr_params[:fq].should include("{!raw f=#{facet_field}}#{value}" )
|
|
174
151
|
end
|
|
175
152
|
end
|
|
176
|
-
|
|
153
|
+
solr_params[:q].should == @mult_word_query
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe "facet_value_to_fq_string", :focus => true do
|
|
158
|
+
it "should use the raw handler for strings" do
|
|
159
|
+
facet_value_to_fq_string("facet_name", "my value").should == "{!raw f=facet_name}my value"
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "should pass integers through" do
|
|
163
|
+
facet_value_to_fq_string("facet_name", 1).should == "facet_name:1"
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it "should pass integer-like strings through" do
|
|
167
|
+
facet_value_to_fq_string("facet_name", "1").should == "facet_name:1"
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it "should pass floats through" do
|
|
171
|
+
facet_value_to_fq_string("facet_name", 1.11).should == "facet_name:1.11"
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "should pass floats through" do
|
|
175
|
+
facet_value_to_fq_string("facet_name", "1.11").should == "facet_name:1.11"
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it "should handle range requests" do
|
|
179
|
+
facet_value_to_fq_string("facet_name", 1..5).should == "facet_name:[1 TO 5]"
|
|
177
180
|
end
|
|
178
181
|
end
|
|
179
182
|
|
|
180
183
|
describe "solr parameters for a field search from config (subject)" do
|
|
181
184
|
before do
|
|
182
|
-
@solr_params =
|
|
185
|
+
@solr_params = solr_search_params( @subject_search_params )
|
|
183
186
|
end
|
|
184
187
|
it "should look up qt from field definition" do
|
|
185
188
|
@solr_params[:qt].should == "search"
|
|
@@ -203,13 +206,13 @@ describe 'Blacklight::SolrHelper' do
|
|
|
203
206
|
@solr_params["spellcheck.q"].should == "wome"
|
|
204
207
|
end
|
|
205
208
|
it "should include facet.field from default_solr_params" do
|
|
206
|
-
@solr_params[:"facet.field"].should ==
|
|
209
|
+
@solr_params[:"facet.field"].should == blacklight_config[:default_solr_params][:"facet.field"]
|
|
207
210
|
end
|
|
208
211
|
it "should include spellcheck.dictionary from field def solr_parameters" do
|
|
209
212
|
@solr_params[:"spellcheck.dictionary"].should == "subject"
|
|
210
213
|
end
|
|
211
214
|
it "should add on :solr_local_parameters using Solr LocalParams style" do
|
|
212
|
-
params =
|
|
215
|
+
params = solr_search_params( @subject_search_params )
|
|
213
216
|
|
|
214
217
|
#q == "{!pf=$subject_pf $qf=subject_qf} wome", make sure
|
|
215
218
|
#the LocalParams are really there
|
|
@@ -222,45 +225,41 @@ describe 'Blacklight::SolrHelper' do
|
|
|
222
225
|
|
|
223
226
|
describe "overriding of qt parameter" do
|
|
224
227
|
it "should return the correct overriden parameter" do
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
+
def params
|
|
229
|
+
super.merge(:qt => "overridden")
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
solr_search_params[:qt].should == "overridden"
|
|
228
233
|
end
|
|
229
234
|
end
|
|
230
235
|
|
|
231
236
|
describe "with a complex parameter environment" do
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
#re-memoize
|
|
246
|
-
Blacklight.search_field_list(:reload)
|
|
247
|
-
end
|
|
248
|
-
|
|
237
|
+
def blacklight_config
|
|
238
|
+
config = Blacklight::Configuration.new
|
|
239
|
+
config.add_search_field("test_field",
|
|
240
|
+
:display_label => "Test",
|
|
241
|
+
:key=>"test_field",
|
|
242
|
+
:solr_parameters => {:qf => "fieldOne^2.3 fieldTwo fieldThree^0.4", :pf => "", :spellcheck => 'false', :rows => "55", :sort => "request_params_sort" }
|
|
243
|
+
)
|
|
244
|
+
return config
|
|
245
|
+
end
|
|
246
|
+
def params
|
|
247
|
+
{:search_field => "test_field", :q => "test query", "facet.field" => "extra_facet"}
|
|
248
|
+
end
|
|
249
|
+
|
|
249
250
|
it "should merge parameters from search_field definition" do
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
251
|
+
solr_params = solr_search_params
|
|
252
|
+
|
|
253
|
+
solr_params[:qf].should == "fieldOne^2.3 fieldTwo fieldThree^0.4"
|
|
254
|
+
solr_params[:spellcheck].should == 'false'
|
|
254
255
|
end
|
|
255
256
|
it "should merge empty string parameters from search_field definition" do
|
|
256
|
-
|
|
257
|
-
params[:pf].should == ""
|
|
257
|
+
solr_search_params[:pf].should == ""
|
|
258
258
|
end
|
|
259
259
|
|
|
260
260
|
describe "should respect proper precedence of settings, " do
|
|
261
261
|
before do
|
|
262
|
-
@produced_params =
|
|
263
|
-
1+1
|
|
262
|
+
@produced_params = solr_search_params
|
|
264
263
|
end
|
|
265
264
|
|
|
266
265
|
|
|
@@ -269,11 +268,11 @@ describe 'Blacklight::SolrHelper' do
|
|
|
269
268
|
end
|
|
270
269
|
|
|
271
270
|
it "should fall through to BL general defaults for qt not otherwise specified " do
|
|
272
|
-
@produced_params[:qt].should ==
|
|
271
|
+
@produced_params[:qt].should == blacklight_config[:default_solr_params][:qt]
|
|
273
272
|
end
|
|
274
273
|
|
|
275
|
-
it "should take
|
|
276
|
-
@produced_params[:
|
|
274
|
+
it "should take rows from search field definition where specified" do
|
|
275
|
+
@produced_params[:rows].should == "55"
|
|
277
276
|
end
|
|
278
277
|
|
|
279
278
|
it "should take q from request params" do
|
|
@@ -284,67 +283,58 @@ describe 'Blacklight::SolrHelper' do
|
|
|
284
283
|
@produced_params[:"facet.field"].should include("extra_facet")
|
|
285
284
|
end
|
|
286
285
|
|
|
287
|
-
it "should Overwrite request params sort with extra_params sort" do
|
|
288
|
-
@produced_params[:sort].should == "extra_params_sort"
|
|
289
|
-
end
|
|
290
|
-
|
|
291
286
|
end
|
|
292
287
|
end
|
|
293
288
|
|
|
294
289
|
describe "sorting" do
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
produced_params = @solr_helper.solr_search_params
|
|
300
|
-
produced_params[:sort].should == 'solr_test_field asc'
|
|
301
|
-
|
|
302
|
-
Blacklight.config[:sort_fields].delete(test_sort_field)
|
|
290
|
+
|
|
291
|
+
it "should send the default sort parameter to solr" do
|
|
292
|
+
solr_search_params[:sort].should == 'score desc, pub_date_sort desc, title_sort asc'
|
|
303
293
|
end
|
|
304
294
|
|
|
305
295
|
it "should not send a sort parameter to solr if the sort value is blank" do
|
|
306
|
-
|
|
307
|
-
|
|
296
|
+
def blacklight_config
|
|
297
|
+
config = Blacklight::Configuration.new
|
|
298
|
+
config.add_sort_field('', :label => 'test')
|
|
299
|
+
return config
|
|
300
|
+
end
|
|
308
301
|
|
|
309
|
-
produced_params =
|
|
302
|
+
produced_params = solr_search_params
|
|
310
303
|
produced_params.should_not have_key(:sort)
|
|
311
|
-
|
|
312
|
-
Blacklight.config[:sort_fields].delete(test_sort_field)
|
|
313
304
|
end
|
|
314
305
|
|
|
315
306
|
it "should pass through user sort parameters" do
|
|
316
|
-
produced_params =
|
|
307
|
+
produced_params = solr_search_params( :sort => 'solr_test_field desc' )
|
|
317
308
|
produced_params[:sort].should == 'solr_test_field desc'
|
|
318
309
|
end
|
|
319
310
|
end
|
|
320
311
|
|
|
321
312
|
describe "for :solr_local_parameters config" do
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
:
|
|
335
|
-
|
|
336
|
-
:pf => "you'll have \" to escape this"
|
|
337
|
-
},
|
|
338
|
-
:solr_parameters => {
|
|
339
|
-
:qf => "someField^1000",
|
|
340
|
-
:ps => "2"
|
|
341
|
-
}
|
|
313
|
+
def blacklight_config
|
|
314
|
+
config = Blacklight::Configuration.new
|
|
315
|
+
config.add_search_field(
|
|
316
|
+
"custom_author_key",
|
|
317
|
+
:display_label => "Author",
|
|
318
|
+
:qt => "author_qt",
|
|
319
|
+
:key => "custom_author_key",
|
|
320
|
+
:solr_local_parameters => {
|
|
321
|
+
:qf => "$author_qf",
|
|
322
|
+
:pf => "you'll have \" to escape this"
|
|
323
|
+
},
|
|
324
|
+
:solr_parameters => {
|
|
325
|
+
:qf => "someField^1000",
|
|
326
|
+
:ps => "2"
|
|
342
327
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
328
|
+
)
|
|
329
|
+
return config
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def params
|
|
333
|
+
{:search_field => "custom_author_key", :q => "query"}
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
before do
|
|
337
|
+
@result = solr_search_params
|
|
348
338
|
end
|
|
349
339
|
|
|
350
340
|
it "should pass through ordinary params" do
|
|
@@ -357,27 +347,22 @@ describe 'Blacklight::SolrHelper' do
|
|
|
357
347
|
@result[:q].should include('qf=$author_qf')
|
|
358
348
|
@result[:q].should include('pf=\'you\\\'ll have \\" to escape this\'')
|
|
359
349
|
end
|
|
360
|
-
|
|
361
|
-
after do
|
|
362
|
-
Object.instance_eval{ remove_const :Blacklight }
|
|
363
|
-
Blacklight = @orig_blacklight
|
|
364
|
-
end
|
|
365
350
|
end
|
|
366
351
|
|
|
367
352
|
describe "mapping facet.field" do
|
|
368
353
|
it "should add single additional facet.field from app" do
|
|
369
|
-
solr_params =
|
|
354
|
+
solr_params = solr_search_params( "facet.field" => "additional_facet" )
|
|
370
355
|
solr_params[:"facet.field"].should include("additional_facet")
|
|
371
356
|
solr_params[:"facet.field"].length.should > 1
|
|
372
357
|
end
|
|
373
358
|
it "should map multiple facet.field to additional facet.field" do
|
|
374
|
-
solr_params =
|
|
359
|
+
solr_params = solr_search_params( "facet.field" => ["add_facet1", "add_facet2"] )
|
|
375
360
|
solr_params[:"facet.field"].should include("add_facet1")
|
|
376
361
|
solr_params[:"facet.field"].should include("add_facet2")
|
|
377
362
|
solr_params[:"facet.field"].length.should > 2
|
|
378
363
|
end
|
|
379
364
|
it "should map facets[fields][] to additional facet.field" do
|
|
380
|
-
solr_params =
|
|
365
|
+
solr_params = solr_search_params( "facets" => ["add_facet1", "add_facet2"] )
|
|
381
366
|
solr_params[:"facet.field"].should include("add_facet1")
|
|
382
367
|
solr_params[:"facet.field"].should include("add_facet2")
|
|
383
368
|
solr_params[:"facet.field"].length.should > 2
|
|
@@ -389,7 +374,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
389
374
|
describe "solr_facet_params" do
|
|
390
375
|
before do
|
|
391
376
|
@facet_field = 'format'
|
|
392
|
-
@generated_solr_facet_params =
|
|
377
|
+
@generated_solr_facet_params = solr_facet_params(@facet_field)
|
|
393
378
|
|
|
394
379
|
@sort_key = Blacklight::Solr::FacetPaginator.request_keys[:sort]
|
|
395
380
|
@offset_key = Blacklight::Solr::FacetPaginator.request_keys[:offset]
|
|
@@ -404,30 +389,30 @@ describe 'Blacklight::SolrHelper' do
|
|
|
404
389
|
@generated_solr_facet_params['facet.offset'].should == 0
|
|
405
390
|
end
|
|
406
391
|
it 'uses offset manually set, and converts it to an integer' do
|
|
407
|
-
solr_params =
|
|
392
|
+
solr_params = solr_facet_params(@facet_field, @offset_key => "100")
|
|
408
393
|
solr_params['facet.offset'].should == 100
|
|
409
394
|
end
|
|
410
395
|
it 'defaults limit to 20' do
|
|
411
|
-
solr_params =
|
|
396
|
+
solr_params = solr_facet_params(@facet_field)
|
|
412
397
|
solr_params[:"f.#{@facet_field}.facet.limit"].should == 21
|
|
413
398
|
end
|
|
414
399
|
describe 'if facet_list_limit is defined in controller' do
|
|
415
|
-
|
|
416
|
-
|
|
400
|
+
def facet_list_limit
|
|
401
|
+
1000
|
|
417
402
|
end
|
|
418
403
|
it 'uses controller method for limit' do
|
|
419
|
-
solr_params =
|
|
404
|
+
solr_params = solr_facet_params(@facet_field)
|
|
420
405
|
solr_params[:"f.#{@facet_field}.facet.limit"].should == 1001
|
|
421
406
|
end
|
|
422
407
|
end
|
|
423
408
|
it 'uses sort set manually' do
|
|
424
|
-
solr_params =
|
|
409
|
+
solr_params = solr_facet_params(@facet_field, @sort_key => "index")
|
|
425
410
|
solr_params['facet.sort'].should == 'index'
|
|
426
411
|
end
|
|
427
412
|
it "comes up with the same params as #solr_search_params to constrain context for facet list" do
|
|
428
413
|
search_params = {:q => 'tibetan history', :f=> {:format=>'Book', :language_facet=>'Tibetan'}}
|
|
429
|
-
solr_search_params =
|
|
430
|
-
solr_facet_params =
|
|
414
|
+
solr_search_params = solr_search_params( search_params )
|
|
415
|
+
solr_facet_params = solr_facet_params('format', search_params)
|
|
431
416
|
|
|
432
417
|
solr_search_params.each_pair do |key, value|
|
|
433
418
|
# The specific params used for fetching the facet list we
|
|
@@ -439,25 +424,28 @@ describe 'Blacklight::SolrHelper' do
|
|
|
439
424
|
|
|
440
425
|
end
|
|
441
426
|
end
|
|
442
|
-
describe "for facet limit parameters config ed" do
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
427
|
+
describe "for facet limit parameters config ed" do
|
|
428
|
+
def params
|
|
429
|
+
{:search_field => "test_field", :q => "test query"}
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
before do
|
|
434
|
+
@generated_params = solr_search_params
|
|
448
435
|
end
|
|
449
436
|
|
|
450
437
|
it "should include specifically configged facet limits +1" do
|
|
451
|
-
@generated_params[:"f.
|
|
438
|
+
@generated_params[:"f.subject_topic_facet.facet.limit"].should == 21
|
|
452
439
|
end
|
|
453
440
|
it "should not include a facet limit for a nil key in hash" do
|
|
454
|
-
@generated_params.should_not have_key(:"f.
|
|
441
|
+
@generated_params.should_not have_key(:"f.format.facet.limit")
|
|
455
442
|
@generated_params.should_not have_key(:"facet.limit")
|
|
456
443
|
end
|
|
457
444
|
end
|
|
458
|
-
|
|
445
|
+
|
|
446
|
+
describe "get_facet_pagination", :integration => true do
|
|
459
447
|
before(:each) do
|
|
460
|
-
@facet_paginator =
|
|
448
|
+
@facet_paginator = get_facet_pagination(@facet_field)
|
|
461
449
|
end
|
|
462
450
|
it 'should return a facet paginator' do
|
|
463
451
|
@facet_paginator.should be_a_kind_of(Blacklight::Solr::FacetPaginator)
|
|
@@ -468,12 +456,12 @@ describe 'Blacklight::SolrHelper' do
|
|
|
468
456
|
end
|
|
469
457
|
|
|
470
458
|
# SPECS FOR SEARCH RESULTS FOR QUERY
|
|
471
|
-
describe 'Search Results' do
|
|
459
|
+
describe 'Search Results', :integration => true do
|
|
472
460
|
|
|
473
461
|
describe 'for a sample query returning results' do
|
|
474
462
|
|
|
475
463
|
before(:all) do
|
|
476
|
-
(@solr_response, @document_list) =
|
|
464
|
+
(@solr_response, @document_list) = get_search_results(:q => @all_docs_query)
|
|
477
465
|
end
|
|
478
466
|
|
|
479
467
|
it 'should have a @response.docs list of the same size as @document_list' do
|
|
@@ -496,11 +484,11 @@ describe 'Blacklight::SolrHelper' do
|
|
|
496
484
|
|
|
497
485
|
describe 'for All Docs Query, No Facets' do
|
|
498
486
|
it 'should have non-nil values for required doc fields set in initializer' do
|
|
499
|
-
(solr_response, document_list) =
|
|
487
|
+
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
|
500
488
|
result_docs = document_list
|
|
501
489
|
document = result_docs.first
|
|
502
|
-
document.get(
|
|
503
|
-
document.get(
|
|
490
|
+
document.get(blacklight_config.index.show_link).should_not == nil
|
|
491
|
+
document.get(blacklight_config.index.record_display_type).should_not == nil
|
|
504
492
|
end
|
|
505
493
|
end
|
|
506
494
|
|
|
@@ -508,7 +496,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
508
496
|
|
|
509
497
|
describe "Single Word Query with no Facets" do
|
|
510
498
|
it 'should have results' do
|
|
511
|
-
(solr_response, document_list) =
|
|
499
|
+
(solr_response, document_list) = get_search_results(:q => @single_word_query)
|
|
512
500
|
solr_response.docs.size.should == document_list.size
|
|
513
501
|
solr_response.docs.size.should > 0
|
|
514
502
|
end
|
|
@@ -517,7 +505,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
517
505
|
describe "Multiple Words Query with No Facets" do
|
|
518
506
|
it 'should have results' do
|
|
519
507
|
|
|
520
|
-
(solr_response, document_list) =
|
|
508
|
+
(solr_response, document_list) = get_search_results(:q => @mult_word_query)
|
|
521
509
|
solr_response.docs.size.should == document_list.size
|
|
522
510
|
solr_response.docs.size.should > 0
|
|
523
511
|
end
|
|
@@ -525,7 +513,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
525
513
|
|
|
526
514
|
describe "One Facet, No Query" do
|
|
527
515
|
it 'should have results' do
|
|
528
|
-
(solr_response, document_list) =
|
|
516
|
+
(solr_response, document_list) = get_search_results(:f => @single_facet)
|
|
529
517
|
solr_response.docs.size.should == document_list.size
|
|
530
518
|
solr_response.docs.size.should > 0
|
|
531
519
|
end
|
|
@@ -533,7 +521,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
533
521
|
|
|
534
522
|
describe "Mult Facets, No Query" do
|
|
535
523
|
it 'should have results' do
|
|
536
|
-
(solr_response, document_list) =
|
|
524
|
+
(solr_response, document_list) = get_search_results(:f => @multi_facets)
|
|
537
525
|
solr_response.docs.size.should == document_list.size
|
|
538
526
|
solr_response.docs.size.should > 0
|
|
539
527
|
end
|
|
@@ -541,7 +529,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
541
529
|
|
|
542
530
|
describe "Single Word Query with One Facet" do
|
|
543
531
|
it 'should have results' do
|
|
544
|
-
(solr_response, document_list) =
|
|
532
|
+
(solr_response, document_list) = get_search_results(:q => @single_word_query, :f => @single_facet)
|
|
545
533
|
solr_response.docs.size.should == document_list.size
|
|
546
534
|
solr_response.docs.size.should > 0
|
|
547
535
|
end
|
|
@@ -549,7 +537,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
549
537
|
|
|
550
538
|
describe "Multiple Words Query with Multiple Facets" do
|
|
551
539
|
it 'should have results' do
|
|
552
|
-
(solr_response, document_list) =
|
|
540
|
+
(solr_response, document_list) = get_search_results(:q => @mult_word_query, :f => @multi_facets)
|
|
553
541
|
solr_response.docs.size.should == document_list.size
|
|
554
542
|
solr_response.docs.size.should > 0
|
|
555
543
|
end
|
|
@@ -557,7 +545,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
557
545
|
|
|
558
546
|
describe "for All Docs Query and One Facet" do
|
|
559
547
|
it 'should have results' do
|
|
560
|
-
(solr_response, document_list) =
|
|
548
|
+
(solr_response, document_list) = get_search_results(:q => @all_docs_query, :f => @single_facet)
|
|
561
549
|
solr_response.docs.size.should == document_list.size
|
|
562
550
|
solr_response.docs.size.should > 0
|
|
563
551
|
end
|
|
@@ -567,7 +555,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
567
555
|
|
|
568
556
|
describe "for Query Without Results and No Facet" do
|
|
569
557
|
it 'should have no results and not raise error' do
|
|
570
|
-
(solr_response, document_list) =
|
|
558
|
+
(solr_response, document_list) = get_search_results(:q => @no_docs_query)
|
|
571
559
|
solr_response.docs.size.should == document_list.size
|
|
572
560
|
solr_response.docs.size.should == 0
|
|
573
561
|
end
|
|
@@ -575,7 +563,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
575
563
|
|
|
576
564
|
describe "for Query Without Results and One Facet" do
|
|
577
565
|
it 'should have no results and not raise error' do
|
|
578
|
-
(solr_response, document_list) =
|
|
566
|
+
(solr_response, document_list) = get_search_results(:q => @no_docs_query, :f => @single_facet)
|
|
579
567
|
solr_response.docs.size.should == document_list.size
|
|
580
568
|
solr_response.docs.size.should == 0
|
|
581
569
|
end
|
|
@@ -583,30 +571,23 @@ describe 'Blacklight::SolrHelper' do
|
|
|
583
571
|
|
|
584
572
|
describe "for All Docs Query and Bad Facet" do
|
|
585
573
|
it 'should have no results and not raise error' do
|
|
586
|
-
(solr_response, document_list) =
|
|
574
|
+
(solr_response, document_list) = get_search_results(:q => @all_docs_query, :f => @bad_facet)
|
|
587
575
|
solr_response.docs.size.should == document_list.size
|
|
588
576
|
solr_response.docs.size.should == 0
|
|
589
577
|
end
|
|
590
578
|
end
|
|
591
579
|
|
|
592
|
-
|
|
593
|
-
it "should have a list of field names for index_view_fields" do
|
|
594
|
-
Blacklight.config[:index_fields].should_not be_nil
|
|
595
|
-
Blacklight.config[:index_fields][:field_names].should be_instance_of(Array)
|
|
596
|
-
Blacklight.config[:index_fields][:field_names].length.should > 0
|
|
597
|
-
Blacklight.config[:index_fields][:field_names][0].should_not == nil
|
|
598
|
-
end
|
|
599
|
-
end
|
|
580
|
+
|
|
600
581
|
|
|
601
582
|
|
|
602
583
|
end # Search Results
|
|
603
584
|
|
|
604
585
|
|
|
605
586
|
# SPECS FOR SEARCH RESULTS FOR FACETS
|
|
606
|
-
describe 'Facets in Search Results for All Docs Query' do
|
|
587
|
+
describe 'Facets in Search Results for All Docs Query', :integration => true do
|
|
607
588
|
|
|
608
589
|
before(:all) do
|
|
609
|
-
(solr_response, document_list) =
|
|
590
|
+
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
|
610
591
|
@facets = solr_response.facets
|
|
611
592
|
end
|
|
612
593
|
|
|
@@ -614,7 +595,7 @@ describe 'Blacklight::SolrHelper' do
|
|
|
614
595
|
@facets.size.should > 1
|
|
615
596
|
end
|
|
616
597
|
it 'should have all facets specified in initializer' do
|
|
617
|
-
|
|
598
|
+
blacklight_config[:default_solr_params][:"facet.field"].each do |field|
|
|
618
599
|
@facets.find {|f| f.name == field}.should_not be_nil
|
|
619
600
|
end
|
|
620
601
|
end
|
|
@@ -644,40 +625,40 @@ describe 'Blacklight::SolrHelper' do
|
|
|
644
625
|
|
|
645
626
|
|
|
646
627
|
# SPECS FOR SEARCH RESULTS FOR PAGING
|
|
647
|
-
describe 'Paging' do
|
|
628
|
+
describe 'Paging', :integration => true do
|
|
648
629
|
|
|
649
630
|
it 'should start with first results by default' do
|
|
650
|
-
(solr_response, document_list) =
|
|
631
|
+
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
|
651
632
|
solr_response.params[:start].to_i.should == 0
|
|
652
633
|
end
|
|
653
634
|
it 'should have number of results (per page) set in initializer, by default' do
|
|
654
|
-
(solr_response, document_list) =
|
|
635
|
+
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
|
655
636
|
solr_response.docs.size.should == document_list.size
|
|
656
|
-
solr_response.docs.size.should ==
|
|
637
|
+
solr_response.docs.size.should == blacklight_config[:default_solr_params][:rows]
|
|
657
638
|
end
|
|
658
639
|
|
|
659
640
|
it 'should get number of results per page requested' do
|
|
660
641
|
num_results = 3 # non-default value
|
|
661
|
-
(solr_response1, document_list1) =
|
|
642
|
+
(solr_response1, document_list1) = get_search_results(:q => @all_docs_query, :per_page => num_results)
|
|
662
643
|
solr_response1.docs.size.should == document_list1.size
|
|
663
644
|
solr_response1.docs.size.should == num_results
|
|
664
645
|
end
|
|
665
646
|
|
|
666
647
|
it 'should skip appropriate number of results when requested - default per page' do
|
|
667
648
|
page = 3
|
|
668
|
-
(solr_response2, document_list2) =
|
|
669
|
-
solr_response2.params[:start].to_i.should ==
|
|
649
|
+
(solr_response2, document_list2) = get_search_results(:q => @all_docs_query, :page => page)
|
|
650
|
+
solr_response2.params[:start].to_i.should == blacklight_config[:default_solr_params][:rows] * (page-1)
|
|
670
651
|
end
|
|
671
652
|
it 'should skip appropriate number of results when requested - non-default per page' do
|
|
672
653
|
page = 3
|
|
673
654
|
num_results = 3
|
|
674
|
-
(solr_response2a, document_list2a) =
|
|
655
|
+
(solr_response2a, document_list2a) = get_search_results(:q => @all_docs_query, :per_page => num_results, :page => page)
|
|
675
656
|
solr_response2a.params[:start].to_i.should == num_results * (page-1)
|
|
676
657
|
end
|
|
677
658
|
|
|
678
659
|
it 'should have no results when prompted for page after last result' do
|
|
679
660
|
big = 5000
|
|
680
|
-
(solr_response3, document_list3) =
|
|
661
|
+
(solr_response3, document_list3) = get_search_results(:q => @all_docs_query, :rows => big, :page => big)
|
|
681
662
|
solr_response3.docs.size.should == document_list3.size
|
|
682
663
|
solr_response3.docs.size.should == 0
|
|
683
664
|
end
|
|
@@ -685,12 +666,12 @@ describe 'Blacklight::SolrHelper' do
|
|
|
685
666
|
it 'should show first results when prompted for page before first result' do
|
|
686
667
|
# FIXME: should it show first results, or should it throw an error for view to deal w?
|
|
687
668
|
# Solr throws an error for a negative start value
|
|
688
|
-
(solr_response4, document_list4) =
|
|
669
|
+
(solr_response4, document_list4) = get_search_results(:q => @all_docs_query, :page => '-1')
|
|
689
670
|
solr_response4.params[:start].to_i.should == 0
|
|
690
671
|
end
|
|
691
672
|
it 'should have results available when asked for more than are in response' do
|
|
692
673
|
big = 5000
|
|
693
|
-
(solr_response5, document_list5) =
|
|
674
|
+
(solr_response5, document_list5) = get_search_results(:q => @all_docs_query, :rows => big, :page => 1)
|
|
694
675
|
solr_response5.docs.size.should == document_list5.size
|
|
695
676
|
solr_response5.docs.size.should > 0
|
|
696
677
|
end
|
|
@@ -698,16 +679,16 @@ describe 'Blacklight::SolrHelper' do
|
|
|
698
679
|
end # page specs
|
|
699
680
|
|
|
700
681
|
# SPECS FOR SINGLE DOCUMENT REQUESTS
|
|
701
|
-
describe 'Get Document By Id' do
|
|
682
|
+
describe 'Get Document By Id', :integration => true do
|
|
702
683
|
before(:all) do
|
|
703
684
|
@doc_id = '2007020969'
|
|
704
685
|
@bad_id = "redrum"
|
|
705
|
-
@response2, @document =
|
|
686
|
+
@response2, @document = get_solr_response_for_doc_id(@doc_id)
|
|
706
687
|
end
|
|
707
688
|
|
|
708
689
|
it "should raise Blacklight::InvalidSolrID for an unknown id" do
|
|
709
690
|
lambda {
|
|
710
|
-
|
|
691
|
+
get_solr_response_for_doc_id(@bad_id)
|
|
711
692
|
}.should raise_error(Blacklight::Exceptions::InvalidSolrID)
|
|
712
693
|
end
|
|
713
694
|
|
|
@@ -721,15 +702,9 @@ describe 'Blacklight::SolrHelper' do
|
|
|
721
702
|
@document.id.should == @doc_id
|
|
722
703
|
end
|
|
723
704
|
it 'should have non-nil values for required fields set in initializer' do
|
|
724
|
-
@document.get(
|
|
725
|
-
@document.get(
|
|
726
|
-
@document.get(
|
|
727
|
-
end
|
|
728
|
-
it "should have a list of field names for show_view_fields" do
|
|
729
|
-
Blacklight.config[:show_fields].should_not be_nil
|
|
730
|
-
Blacklight.config[:show_fields][:field_names].should be_instance_of(Array)
|
|
731
|
-
Blacklight.config[:show_fields][:field_names].length.should > 0
|
|
732
|
-
Blacklight.config[:show_fields][:field_names][0].should_not == nil
|
|
705
|
+
@document.get(blacklight_config[:show][:html_title]).should_not == nil
|
|
706
|
+
@document.get(blacklight_config[:show][:heading]).should_not == nil
|
|
707
|
+
@document.get(blacklight_config[:show][:display_type]).should_not == nil
|
|
733
708
|
end
|
|
734
709
|
end
|
|
735
710
|
|
|
@@ -744,20 +719,18 @@ describe 'Blacklight::SolrHelper' do
|
|
|
744
719
|
end
|
|
745
720
|
=end
|
|
746
721
|
it "should respect the configuration-supplied unique id" do
|
|
747
|
-
doc_params =
|
|
722
|
+
doc_params = solr_doc_params('"Strong Medicine speaks"')
|
|
748
723
|
doc_params[:id].should == '"Strong Medicine speaks"'
|
|
749
724
|
end
|
|
750
725
|
end
|
|
751
726
|
|
|
752
|
-
|
|
753
|
-
# flow of control is such that the variables can't be instance variables
|
|
754
|
-
# (or at least not for me - Naomi)
|
|
727
|
+
|
|
755
728
|
|
|
756
729
|
# SPECS FOR SINGLE DOCUMENT VIA SEARCH
|
|
757
|
-
describe "Get Document Via Search" do
|
|
730
|
+
describe "Get Document Via Search", :integration => true do
|
|
758
731
|
before(:all) do
|
|
759
732
|
@doc_row = 3
|
|
760
|
-
@doc =
|
|
733
|
+
@doc = get_single_doc_via_search(@doc_row, :q => @all_docs_query)
|
|
761
734
|
end
|
|
762
735
|
=begin
|
|
763
736
|
# can't test these here, because the method only returns the document
|
|
@@ -780,28 +753,28 @@ describe 'Blacklight::SolrHelper' do
|
|
|
780
753
|
end
|
|
781
754
|
|
|
782
755
|
it 'should have non-nil values for required fields set in initializer' do
|
|
783
|
-
@doc[
|
|
784
|
-
@doc[
|
|
785
|
-
@doc[
|
|
756
|
+
@doc[blacklight_config.show.html_title].should_not == nil
|
|
757
|
+
@doc[blacklight_config.show.heading].should_not == nil
|
|
758
|
+
@doc[blacklight_config.show.display_type].should_not == nil
|
|
786
759
|
end
|
|
787
760
|
|
|
788
761
|
it "should limit search result by facets when supplied" do
|
|
789
|
-
doc2 =
|
|
762
|
+
doc2 = get_single_doc_via_search(@doc_row , :q => @all_docs_query, :f => @multi_facets)
|
|
790
763
|
doc2[:id].should_not == nil
|
|
791
764
|
end
|
|
792
765
|
|
|
793
766
|
end
|
|
794
767
|
|
|
795
768
|
# SPECS FOR SPELLING SUGGESTIONS VIA SEARCH
|
|
796
|
-
describe "Searches should return spelling suggestions" do
|
|
769
|
+
describe "Searches should return spelling suggestions", :integration => true do
|
|
797
770
|
it 'search results for just-poor-enough-query term should have (multiple) spelling suggestions' do
|
|
798
|
-
(solr_response, document_list) =
|
|
771
|
+
(solr_response, document_list) = get_search_results({:q => 'boo'})
|
|
799
772
|
solr_response.spelling.words.should include('bon')
|
|
800
773
|
solr_response.spelling.words.should include('bod') #for multiple suggestions
|
|
801
774
|
end
|
|
802
775
|
|
|
803
776
|
it 'search results for just-poor-enough-query term should have multiple spelling suggestions' do
|
|
804
|
-
(solr_response, document_list) =
|
|
777
|
+
(solr_response, document_list) = get_search_results({:q => 'politica'})
|
|
805
778
|
solr_response.spelling.words.should include('policy') # less freq
|
|
806
779
|
solr_response.spelling.words.should include('politics') # more freq
|
|
807
780
|
solr_response.spelling.words.should include('political') # more freq
|
|
@@ -814,17 +787,17 @@ describe 'Blacklight::SolrHelper' do
|
|
|
814
787
|
end
|
|
815
788
|
|
|
816
789
|
it "title search results for just-poor-enough query term should have spelling suggestions" do
|
|
817
|
-
(solr_response, document_list) =
|
|
790
|
+
(solr_response, document_list) = get_search_results({:q => 'yehudiyam', :qt => 'search', :"spellcheck.dictionary" => "title"})
|
|
818
791
|
solr_response.spelling.words.should include('yehudiyim')
|
|
819
792
|
end
|
|
820
793
|
|
|
821
794
|
it "author search results for just-poor-enough-query term should have spelling suggestions" do
|
|
822
|
-
(solr_response, document_list) =
|
|
795
|
+
(solr_response, document_list) = get_search_results({:q => 'shirma', :qt => 'search', :"spellcheck.dictionary" => "author"})
|
|
823
796
|
solr_response.spelling.words.should include('sharma')
|
|
824
797
|
end
|
|
825
798
|
|
|
826
799
|
it "subject search results for just-poor-enough-query term should have spelling suggestions" do
|
|
827
|
-
(solr_response, document_list) =
|
|
800
|
+
(solr_response, document_list) = get_search_results({:q => 'wome', :qt => 'search', :"spellcheck.dictionary" => "subject"})
|
|
828
801
|
solr_response.spelling.words.should include('women')
|
|
829
802
|
end
|
|
830
803
|
|
|
@@ -838,71 +811,79 @@ describe 'Blacklight::SolrHelper' do
|
|
|
838
811
|
describe "facet_limit_for" do
|
|
839
812
|
|
|
840
813
|
it "should return specified value for facet_field specified" do
|
|
841
|
-
|
|
814
|
+
facet_limit_for("subject_topic_facet").should == blacklight_config.facet_fields["subject_topic_facet"].limit
|
|
815
|
+
end
|
|
816
|
+
it "should generate proper solr param" do
|
|
817
|
+
solr_search_params[:"f.subject_topic_facet.facet.limit"].should == 21
|
|
842
818
|
end
|
|
843
|
-
|
|
844
|
-
|
|
819
|
+
|
|
820
|
+
it "facet_limit_hash should return hash with key being facet_field and value being configured limit" do
|
|
821
|
+
# facet_limit_hash has been removed from solrhelper in refactor. should it go back?
|
|
822
|
+
pending "facet_limit_hash has been removed from solrhelper in refactor. should it go back?"
|
|
823
|
+
facet_limit_hash.should == blacklight_config[:facet][:limits]
|
|
845
824
|
end
|
|
846
825
|
it "should handle no facet_limits in config" do
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
Blacklight.config[:facet][:limits].has_key?("subject_topic_facet").should be_true
|
|
858
|
-
@solr_helper.solr_search_params[:"f.subject_topic_facet.facet.limit"].should == 21
|
|
859
|
-
fl = Blacklight.config[:facet][:limits]
|
|
860
|
-
Blacklight.config[:facet][:limits] = nil
|
|
861
|
-
@solr_helper.solr_search_params.has_key?(:"f.subject_topic_facet.facet.limit").should be_false
|
|
862
|
-
Blacklight.config[:facet][:limits] = fl
|
|
826
|
+
def blacklight_config
|
|
827
|
+
config = super.inheritable_copy
|
|
828
|
+
config.facet_fields = {}
|
|
829
|
+
return config
|
|
830
|
+
end
|
|
831
|
+
|
|
832
|
+
facet_limit_for("subject_topic_facet").should be_nil
|
|
833
|
+
|
|
834
|
+
solr_search_params.should_not have_key(:"f.subject_topic_facet.facet.limit")
|
|
835
|
+
|
|
863
836
|
end
|
|
837
|
+
|
|
864
838
|
describe "for 'true' configured values" do
|
|
865
839
|
it "should return nil if no @response available" do
|
|
866
|
-
|
|
840
|
+
facet_limit_for("some_unknown_field").should be_nil
|
|
867
841
|
end
|
|
868
|
-
it "should get from @response facet.limit if available" do
|
|
869
|
-
|
|
870
|
-
|
|
842
|
+
it "should get from @response facet.limit if available" do
|
|
843
|
+
# Okay, this is cheesy, since we included SolrHelper directly
|
|
844
|
+
# into our example groups, we need to set an iVar here, so it will
|
|
845
|
+
# use it.
|
|
846
|
+
@response = {"responseHeader" => {"params" => {"facet.limit" => 11}}}
|
|
847
|
+
facet_limit_for("language_facet").should == 10
|
|
871
848
|
end
|
|
872
849
|
it "should get from specific field in @response if available" do
|
|
873
|
-
@
|
|
874
|
-
|
|
850
|
+
@response = {"responseHeader" => {"params" => {"facet.limit" => 11,"f.language_facet.facet.limit" => 16}}}
|
|
851
|
+
facet_limit_for("language_facet").should == 15
|
|
875
852
|
end
|
|
876
853
|
end
|
|
877
854
|
end
|
|
878
855
|
|
|
879
856
|
describe "with max per page enforced" do
|
|
857
|
+
def blacklight_config
|
|
858
|
+
config = Blacklight::Configuration.new
|
|
859
|
+
config.max_per_page = 123
|
|
860
|
+
return config
|
|
861
|
+
end
|
|
862
|
+
|
|
863
|
+
it "should enforce max_per_page against all parameters" do
|
|
864
|
+
blacklight_config.max_per_page.should == 123
|
|
865
|
+
solr_search_params(:per_page => 98765)[:rows].should == 123
|
|
866
|
+
end
|
|
867
|
+
end
|
|
868
|
+
|
|
869
|
+
describe "#get_solr_response_for_field_values" do
|
|
880
870
|
before do
|
|
881
|
-
|
|
882
|
-
@
|
|
883
|
-
@solr_helper_with_params.params = {:search_field => "test_field", :per_page => 12345, :q => "test query", "facet.field" => "extra_facet"}
|
|
871
|
+
@mock_response = mock()
|
|
872
|
+
@mock_response.stub(:docs => [])
|
|
884
873
|
end
|
|
885
|
-
|
|
874
|
+
it "should contruct a solr query based on the field and value pair" do
|
|
875
|
+
self.should_receive(:find).with(hash_including(:q => "field_name:(value)")).and_return(@mock_response)
|
|
876
|
+
get_solr_response_for_field_values('field_name', 'value')
|
|
886
877
|
end
|
|
887
878
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
1+1
|
|
892
|
-
end
|
|
893
|
-
it "should take per_page from search field definition where specified" do
|
|
894
|
-
@produced_params[:per_page].should == "100"
|
|
895
|
-
end
|
|
879
|
+
it "should OR multiple values together" do
|
|
880
|
+
self.should_receive(:find).with(hash_including(:q => "field_name:(a OR b)")).and_return(@mock_response)
|
|
881
|
+
get_solr_response_for_field_values('field_name', ['a', 'b'])
|
|
896
882
|
end
|
|
897
883
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
1+1
|
|
902
|
-
end
|
|
903
|
-
it "should take per_page from search field definition where specified" do
|
|
904
|
-
@produced_params[:per_page].should == "100"
|
|
905
|
-
end
|
|
884
|
+
it "should escape crazy identifiers" do
|
|
885
|
+
self.should_receive(:find).with(hash_including(:q => "field_name:(\"h://\\\"\\\'\")")).and_return(@mock_response)
|
|
886
|
+
get_solr_response_for_field_values('field_name', 'h://"\'')
|
|
906
887
|
end
|
|
907
888
|
end
|
|
908
889
|
|