blacklight 4.9.0 → 5.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +22 -12
- data/Gemfile +3 -40
- data/LICENSE +1 -2
- data/README.md +1 -2
- data/Rakefile +0 -4
- data/VERSION +1 -1
- data/app/assets/images/blacklight/logo.png +0 -0
- data/app/assets/javascripts/blacklight/ajax_modal.js +190 -0
- data/app/assets/javascripts/blacklight/blacklight.js +7 -17
- data/app/assets/javascripts/blacklight/checkbox_submit.js +1 -1
- data/app/assets/stylesheets/blacklight/{_blacklight_base.scss → _blacklight_base.css.scss} +0 -21
- data/app/assets/stylesheets/blacklight/_bookmark.css.scss +4 -0
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +192 -0
- data/app/assets/stylesheets/blacklight/_facets.css.scss +141 -0
- data/app/assets/stylesheets/blacklight/{_group.scss → _group.css.scss} +1 -1
- data/app/assets/stylesheets/blacklight/_header.css.scss +44 -0
- data/app/assets/stylesheets/blacklight/_layout.css.scss +5 -0
- data/app/assets/stylesheets/blacklight/{_modal.scss → _modal.css.scss} +7 -7
- data/app/assets/stylesheets/blacklight/_search_history.css.scss +20 -0
- data/app/assets/stylesheets/blacklight/{blacklight.scss → blacklight.css.scss} +0 -0
- data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +14 -0
- data/app/controllers/bookmarks_controller.rb +0 -4
- data/app/controllers/feedback_controller.rb +0 -4
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +45 -155
- data/app/helpers/blacklight/catalog_helper_behavior.rb +8 -41
- data/app/helpers/blacklight/facets_helper_behavior.rb +20 -43
- data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +2 -9
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +9 -14
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +6 -6
- data/app/views/_flash_msg.html.erb +9 -2
- data/app/views/_user_util_links.html.erb +29 -15
- data/app/views/bookmarks/_tools.html.erb +4 -7
- data/app/views/bookmarks/index.html.erb +3 -2
- data/app/views/catalog/_citation.html.erb +1 -1
- data/app/views/catalog/_constraints.html.erb +1 -1
- data/app/views/catalog/_constraints_element.html.erb +12 -8
- data/app/views/catalog/_did_you_mean.html.erb +2 -2
- data/app/views/catalog/_document_header.html.erb +3 -3
- data/app/views/catalog/_email_form.html.erb +10 -10
- data/app/views/catalog/_facet_layout.html.erb +11 -3
- data/app/views/catalog/_facet_limit.html.erb +7 -7
- data/app/views/catalog/_facet_pagination.html.erb +8 -7
- data/app/views/catalog/_facet_pivot.html.erb +3 -1
- data/app/views/catalog/_facets.html.erb +12 -9
- data/app/views/catalog/_paginate_compact.html.erb +1 -7
- data/app/views/catalog/_per_page_widget.html.erb +5 -8
- data/app/views/catalog/_previous_next_doc.html.erb +11 -9
- data/app/views/catalog/_refworks_form.html.erb +3 -4
- data/app/views/catalog/_results_pagination.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +16 -14
- data/app/views/catalog/_show_sidebar.html.erb +7 -9
- data/app/views/catalog/_show_tools.html.erb +13 -7
- data/app/views/catalog/_sms_form.html.erb +8 -8
- data/app/views/catalog/_sort_and_per_page.html.erb +4 -6
- data/app/views/catalog/_sort_widget.html.erb +5 -6
- data/app/views/catalog/email.html.erb +1 -1
- data/app/views/catalog/facet.html.erb +2 -8
- data/app/views/catalog/index.html.erb +11 -6
- data/app/views/catalog/show.html.erb +5 -5
- data/app/views/catalog/sms.html.erb +1 -1
- data/app/views/catalog/sms_sent.html.erb +1 -1
- data/app/views/feedback/complete.html.erb +2 -2
- data/app/views/feedback/show.html.erb +1 -1
- data/app/views/kaminari/blacklight/_paginator.html.erb +1 -1
- data/app/views/kaminari/blacklight_compact/_paginator.html.erb +25 -5
- data/app/views/layouts/blacklight.html.erb +23 -23
- data/app/views/saved_searches/index.html.erb +2 -2
- data/app/views/search_history/index.html.erb +5 -7
- data/app/views/shared/_header_navbar.html.erb +23 -23
- data/blacklight.gemspec +10 -13
- data/config/locales/blacklight.en.yml +1 -12
- data/config/locales/blacklight.fr.yml +1 -12
- data/gemfiles/rails3.gemfile +21 -0
- data/gemfiles/rails4.gemfile +20 -0
- data/lib/blacklight.rb +0 -8
- data/lib/blacklight/base.rb +0 -2
- data/lib/blacklight/catalog.rb +6 -32
- data/lib/blacklight/catalog/search_context.rb +8 -48
- data/lib/blacklight/configurable.rb +2 -1
- data/lib/blacklight/configuration.rb +1 -2
- data/lib/blacklight/configuration/facet_field.rb +0 -2
- data/lib/blacklight/engine.rb +3 -3
- data/lib/blacklight/legacy_controller_methods.rb +1 -64
- data/lib/blacklight/rails/routes.rb +17 -0
- data/lib/blacklight/routes.rb +46 -40
- data/lib/blacklight/solr.rb +1 -0
- data/lib/blacklight/solr/document.rb +21 -42
- data/lib/blacklight/solr/facet_paginator.rb +30 -54
- data/lib/blacklight/solr/request.rb +45 -0
- data/lib/blacklight/solr_helper.rb +16 -53
- data/lib/blacklight/solr_response.rb +0 -6
- data/lib/blacklight/user.rb +2 -7
- data/lib/blacklight/utils.rb +1 -9
- data/lib/generators/blacklight/assets_generator.rb +0 -14
- data/lib/generators/blacklight/blacklight_generator.rb +17 -14
- data/lib/generators/blacklight/templates/blacklight.css.scss +3 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +4 -1
- data/lib/railties/blacklight.rake +3 -1
- data/solr/sample_solr_documents.yml +641 -0
- data/spec/controllers/application_controller_spec.rb +5 -21
- data/spec/controllers/bookmarks_controller_spec.rb +11 -11
- data/spec/controllers/catalog_controller_spec.rb +122 -119
- data/spec/controllers/search_history_controller_spec.rb +8 -8
- data/spec/features/alternate_controller_spec.rb +5 -5
- data/spec/features/facets_spec.rb +9 -0
- data/spec/features/record_view_spec.rb +1 -1
- data/spec/features/search_filters_spec.rb +97 -41
- data/spec/features/search_results_spec.rb +14 -17
- data/spec/features/search_sort_spec.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +170 -285
- data/spec/helpers/catalog_helper_spec.rb +57 -96
- data/spec/helpers/facets_helper_spec.rb +130 -152
- data/spec/helpers/hash_as_hidden_fields_spec.rb +9 -15
- data/spec/helpers/render_constraints_helper_spec.rb +5 -5
- data/spec/helpers/search_history_constraints_helper_spec.rb +21 -21
- data/spec/lib/blacklight/routes_spec.rb +25 -0
- data/spec/lib/blacklight/solr/request_spec.rb +37 -0
- data/spec/lib/blacklight/solr_response/group_response_spec.rb +2 -2
- data/spec/lib/blacklight_configurable_spec.rb +16 -16
- data/spec/lib/blacklight_configuration_spec.rb +132 -132
- data/spec/lib/blacklight_email_spec.rb +4 -4
- data/spec/lib/blacklight_sms_spec.rb +4 -4
- data/spec/lib/blacklight_solr_document_dublin_core_spec.rb +6 -6
- data/spec/lib/blacklight_solr_document_more_like_this_spec.rb +4 -4
- data/spec/lib/blacklight_solr_document_spec.rb +36 -36
- data/spec/lib/blacklight_solr_response_spec.rb +43 -48
- data/spec/lib/blacklight_spec.rb +6 -14
- data/spec/lib/blacklight_user_spec.rb +5 -9
- data/spec/lib/facet_paginator_spec.rb +59 -51
- data/spec/lib/search_fields_spec.rb +13 -13
- data/spec/lib/solr_helper_spec.rb +258 -304
- data/spec/lib/tasks/blacklight_task_spec.rb +1 -1
- data/spec/lib/utils_spec.rb +16 -46
- data/spec/models/bookmark_spec.rb +6 -7
- data/spec/models/record_mailer_spec.rb +16 -16
- data/spec/models/search_spec.rb +8 -8
- data/spec/models/solr_document_spec.rb +6 -77
- data/spec/routing/catalog_routing_spec.rb +16 -10
- data/spec/spec_helper.rb +7 -7
- data/spec/support/assert_difference.rb +2 -2
- data/spec/support/features.rb +0 -11
- data/spec/support/features/session_helpers.rb +3 -3
- data/spec/support/include_text.rb +2 -2
- data/spec/test_app_templates/Gemfile.extra +10 -2
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -18
- data/spec/views/catalog/_constraints_element.html.erb_spec.rb +13 -13
- data/spec/views/catalog/_document.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_facets.html.erb_spec.rb +13 -14
- data/spec/views/catalog/_index_default.erb_spec.rb +21 -21
- data/spec/views/catalog/_search_header.erb_spec.rb +1 -1
- data/spec/views/catalog/_show_default.erb_spec.rb +21 -21
- data/spec/views/catalog/_show_sidebar.erb_spec.rb +7 -7
- data/spec/views/catalog/_thumbnail_default.erb_spec.rb +3 -3
- data/spec/views/catalog/index.atom.builder_spec.rb +29 -29
- data/spec/views/catalog/index.html.erb_spec.rb +6 -7
- data/tasks/blacklight.rake +8 -2
- metadata +84 -180
- data/app/assets/javascripts/blacklight/css_dropdowns.js +0 -10
- data/app/assets/javascripts/blacklight/facet_expand_contract.js +0 -41
- data/app/assets/javascripts/blacklight/lightbox_dialog.js +0 -70
- data/app/assets/javascripts/blacklight/select_submit.js +0 -27
- data/app/assets/javascripts/blacklight/zebra_stripe.js +0 -13
- data/app/assets/javascripts/improved-modal/bootstrap-modal.js +0 -355
- data/app/assets/javascripts/improved-modal/bootstrap-modalmanager.js +0 -370
- data/app/assets/stylesheets/blacklight/_bookmark.scss +0 -33
- data/app/assets/stylesheets/blacklight/_catalog.scss +0 -255
- data/app/assets/stylesheets/blacklight/_dropdown.scss +0 -57
- data/app/assets/stylesheets/blacklight/_facets.scss +0 -197
- data/app/assets/stylesheets/blacklight/_footer.scss +0 -0
- data/app/assets/stylesheets/blacklight/_header.scss +0 -53
- data/app/assets/stylesheets/blacklight/_layout.scss +0 -10
- data/app/assets/stylesheets/blacklight/_mixins.scss +0 -0
- data/app/assets/stylesheets/blacklight/_print.scss +0 -0
- data/app/assets/stylesheets/blacklight/_responsive.scss +0 -3
- data/app/assets/stylesheets/blacklight/_search_history.scss +0 -42
- data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +0 -49
- data/app/assets/stylesheets/blacklight/responsive_partials/_catalog.scss +0 -5
- data/app/assets/stylesheets/blacklight/responsive_partials/_facets.scss +0 -37
- data/app/assets/stylesheets/blacklight/responsive_partials/_header.scss +0 -30
- data/app/assets/stylesheets/improved-modal/bootstrap-modal.css +0 -217
- data/app/helpers/blacklight/html_head_helper_behavior.rb +0 -118
- data/app/helpers/html_head_helper.rb +0 -3
- data/app/views/catalog/_bookmark_form.html.erb +0 -7
- data/app/views/catalog/_marc_view.html.erb +0 -32
- data/app/views/catalog/librarian_view.html.erb +0 -10
- data/config/routes.rb +0 -17
- data/doc/Atom-Responses.md +0 -90
- data/doc/Blacklight-3.0-Release-Notes-And-Upgrade-Guide.md +0 -107
- data/doc/Blacklight-3.2-Release-Notes-and-Upgrade-Guide.md +0 -191
- data/doc/Blacklight-3.3-release-notes-and-upgrade-guide.md +0 -37
- data/doc/Blacklight-3.4-release-notes-and-upgrade-guide.md +0 -27
- data/doc/Blacklight-3.5-release-notes-and-upgrade-guide.md +0 -44
- data/doc/Blacklight-3.6-release-notes-and-upgrade-guide.md +0 -25
- data/doc/Blacklight-3.7-release-notes-and-upgrade-guide.md +0 -80
- data/doc/Blacklight-3.8-release-notes-and-upgrade-guide.md +0 -11
- data/doc/Blacklight-4.0-release-notes-and-upgrade-guide.md +0 -135
- data/doc/Blacklight-4.1-release-notes-and-upgrade-guide.md +0 -17
- data/doc/Blacklight-4.2-release-notes-and-upgrade-guide.md +0 -25
- data/doc/Blacklight-4.3-release-notes-and-upgrade-guide.md +0 -21
- data/doc/Blacklight-4.4-release-notes-and-upgrade-guide.md +0 -41
- data/doc/Blacklight-Add-ons.md +0 -28
- data/doc/Blacklight-configuration.md +0 -411
- data/doc/Blacklight-on-Heroku.md +0 -135
- data/doc/Code4Lib-2014.md +0 -48
- data/doc/Community-principles.md +0 -44
- data/doc/Configuring-and-Customizing-Blacklight.md +0 -271
- data/doc/Configuring-rails-routes.md +0 -13
- data/doc/Contributing-to-Blacklight.md +0 -25
- data/doc/Examples.md +0 -94
- data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -141
- data/doc/FAQs.md +0 -1
- data/doc/Home.md +0 -80
- data/doc/How-to-release-a-version.md +0 -29
- data/doc/Indexing-your-data-into-solr.md +0 -32
- data/doc/Integration-with-Rails-Footnotes.md +0 -20
- data/doc/Internationalization.md +0 -32
- data/doc/JSON-API.md +0 -17
- data/doc/Pagination.md +0 -51
- data/doc/Providing-your-own-view-templates.md +0 -109
- data/doc/Quickstart.md +0 -115
- data/doc/README_SOLR.md +0 -245
- data/doc/Release-Notes-And-Upgrade-Guides.md +0 -20
- data/doc/Roadmap.md +0 -43
- data/doc/Sunspot-for-indexing.md +0 -46
- data/doc/Theming.md +0 -64
- data/doc/User-Authentication.md +0 -60
- data/doc/testing.md +0 -57
- data/lib/SolrMarc.jar +0 -0
- data/lib/blacklight/mash.rb +0 -19
- data/lib/blacklight/solr/document/marc.rb +0 -71
- data/lib/blacklight/solr/document/marc_export.rb +0 -590
- data/lib/generators/blacklight/marc_generator.rb +0 -66
- data/lib/generators/blacklight/templates/blacklight.scss +0 -4
- data/lib/generators/blacklight/templates/config/SolrMarc/config-test.properties +0 -37
- data/lib/generators/blacklight/templates/config/SolrMarc/config.properties +0 -37
- data/lib/generators/blacklight/templates/config/SolrMarc/index.properties +0 -97
- data/lib/generators/blacklight/templates/config/SolrMarc/index_scripts/dewey.bsh +0 -47
- data/lib/generators/blacklight/templates/config/SolrMarc/index_scripts/format.bsh +0 -126
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/README_MAPS +0 -1
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/callnumber_map.properties +0 -407
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/composition_era_map.properties +0 -56
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/country_map.properties +0 -379
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/format_map.properties +0 -50
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/instrument_map.properties +0 -101
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/language_map.properties +0 -490
- data/lib/railties/solr_marc.rake +0 -162
- data/spec/data/test_data.utf8.mrc +0 -1
- data/spec/features/librarian_view_spec.rb +0 -13
- data/spec/helpers/html_head_helper_spec.rb +0 -164
- data/spec/lib/blacklight_solr_document_marc_spec.rb +0 -89
- data/spec/lib/marc_export_spec.rb +0 -746
- data/spec/lib/tasks/solr_marc_task_spec.rb +0 -60
- data/spec/requests/alternate_controller_spec.rb +0 -16
- data/spec/routing/routes_spec.rb +0 -20
- data/spec/views/catalog/_constraints.html.erb_spec.rb +0 -33
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +0 -49
- data/test_support/data/test_data.utf8.mrc +0 -1
data/spec/lib/blacklight_spec.rb
CHANGED
@@ -2,43 +2,35 @@
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
3
|
|
4
4
|
describe Blacklight do
|
5
|
-
|
6
|
-
around :each do |example|
|
7
|
-
Deprecation.silence(Blacklight) do
|
8
|
-
example.run
|
9
|
-
end
|
10
|
-
end
|
11
5
|
|
12
6
|
context "locate_path" do
|
13
7
|
|
14
8
|
it "should find app/controllers/application_controller.rb" do
|
15
9
|
result = Blacklight.locate_path 'app', 'controllers', 'application_controller.rb'
|
16
|
-
|
10
|
+
result.should_not == nil
|
17
11
|
end
|
18
12
|
|
19
13
|
it "should not find blah.rb" do
|
20
14
|
result = Blacklight.locate_path 'blah.rb'
|
21
|
-
|
15
|
+
result.should == nil
|
22
16
|
end
|
23
17
|
|
24
18
|
end
|
25
19
|
|
26
20
|
context 'root' do
|
27
21
|
|
28
|
-
|
29
|
-
@blroot = File.expand_path(File.join(__FILE__, '..', '..', '..' ))
|
30
|
-
end
|
22
|
+
let(:blroot) { File.expand_path(File.join(__FILE__, '..', '..', '..' )) }
|
31
23
|
|
32
24
|
it 'should return the full path to the BL plugin' do
|
33
|
-
|
25
|
+
Blacklight.root.should == blroot
|
34
26
|
end
|
35
27
|
|
36
28
|
it 'should return the full path to the model directory' do
|
37
|
-
|
29
|
+
Blacklight.models_dir.should == blroot + "/app/models"
|
38
30
|
end
|
39
31
|
|
40
32
|
it 'should return the full path to the controllers directory' do
|
41
|
-
|
33
|
+
Blacklight.controllers_dir.should == blroot + "/app/controllers"
|
42
34
|
end
|
43
35
|
|
44
36
|
end
|
@@ -4,10 +4,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
4
4
|
describe "Blacklight::User" do
|
5
5
|
|
6
6
|
subject { User.create! :email => 'xyz@example.com', :password => 'xyz12345' }
|
7
|
-
|
8
|
-
around(:each) do |example|
|
9
|
-
Deprecation.silence(Blacklight::User) { example.run }
|
10
|
-
end
|
11
7
|
|
12
8
|
def mock_bookmark document_id
|
13
9
|
Bookmark.new :document_id => document_id
|
@@ -26,7 +22,7 @@ describe "Blacklight::User" do
|
|
26
22
|
|
27
23
|
it "should know if it has a bookmarked document" do
|
28
24
|
subject.bookmarks << mock_bookmark(1)
|
29
|
-
expect(subject.document_is_bookmarked?(1)).to
|
25
|
+
expect(subject.document_is_bookmarked?(1)).to be_true
|
30
26
|
end
|
31
27
|
|
32
28
|
it "should be able to create bookmarks in batches" do
|
@@ -35,7 +31,7 @@ describe "Blacklight::User" do
|
|
35
31
|
@md3 = { :document_id => 3 }
|
36
32
|
|
37
33
|
subject.documents_to_bookmark= [@md1,@md2,@md3]
|
38
|
-
expect(subject.bookmarks
|
34
|
+
expect(subject.bookmarks).to have(3).bookmarks
|
39
35
|
expect(subject.bookmarked_document_ids).to include("1","2","3")
|
40
36
|
|
41
37
|
end
|
@@ -44,19 +40,19 @@ describe "Blacklight::User" do
|
|
44
40
|
subject.bookmarks << mock_bookmark(1)
|
45
41
|
|
46
42
|
@md1 = { :document_id => 1 }
|
47
|
-
|
43
|
+
subject.bookmarks.should_not_receive(:create).with(@md1)
|
48
44
|
|
49
45
|
subject.bookmarks.push(mock_bookmark(1))
|
50
46
|
subject.documents_to_bookmark=[@md1]
|
51
47
|
end
|
52
48
|
|
53
49
|
it "should know if it doesn't have a search" do
|
54
|
-
|
50
|
+
subject.has_searches?.should == false
|
55
51
|
end
|
56
52
|
|
57
53
|
it "should know if it has a search" do
|
58
54
|
subject.searches << Search.new
|
59
|
-
|
55
|
+
subject.has_searches?.should == true
|
60
56
|
end
|
61
57
|
|
62
58
|
end
|
@@ -4,68 +4,76 @@
|
|
4
4
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
5
5
|
|
6
6
|
describe 'Blacklight::Solr::FacetPaginator' do
|
7
|
+
before(:all) do
|
8
|
+
require 'yaml'
|
9
|
+
@seven_facet_values = YAML::load("--- \n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 792\n value: Book\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 65\n value: Musical Score\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 58\n value: Serial\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 48\n value: Musical Recording\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 37\n value: Microform\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 27\n value: Thesis\n- !ruby/object:Blacklight::SolrResponse::Facets::FacetItem \n hits: 0\n value: \n")
|
10
|
+
@six_facet_values = @seven_facet_values.slice(1,6)
|
11
|
+
@limit = 6
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
let(:f3) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '58', value: 'Serial') }
|
11
|
-
let(:f4) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '48', value: 'Musical Recording') }
|
12
|
-
let(:f5) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '37', value: 'Microform') }
|
13
|
-
let(:f6) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '27', value: 'Thesis') }
|
14
|
-
let(:f7) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '0') }
|
15
|
-
let(:seven_facet_values) { [f1, f2, f3, f4, f5, f6, f7] }
|
16
|
-
let(:six_facet_values) { [f1, f2, f3, f4, f5, f6] }
|
17
|
-
let(:limit) { 6 }
|
18
|
-
|
19
|
-
context 'on the first page of two pages' do
|
20
|
-
subject { Blacklight::Solr::FacetPaginator.new(seven_facet_values, limit: limit) }
|
21
|
-
it { should be_first_page }
|
22
|
-
it { should_not be_last_page }
|
23
|
-
its(:current_page) { should eq 1 }
|
24
|
-
its(:prev_page) { should be_nil }
|
25
|
-
its(:next_page) { should eq 2 }
|
26
|
-
it 'should limit items to limit, if limit is smaller than items.length' do
|
27
|
-
expect(subject.items.size).to eq 6
|
28
|
-
end
|
13
|
+
@sort_key = Blacklight::Solr::FacetPaginator.request_keys[:sort]
|
14
|
+
@page_key = Blacklight::Solr::FacetPaginator.request_keys[:page]
|
29
15
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
it { should_not be_first_page }
|
34
|
-
it { should be_last_page }
|
35
|
-
its(:current_page) { should eq 2 }
|
36
|
-
its(:prev_page) { should eq 1 }
|
37
|
-
its(:next_page) { should be_nil }
|
38
|
-
it 'should return all items when limit is greater than items.length' do
|
39
|
-
expect(subject.items.size).to eq 1
|
16
|
+
context 'when there are limit+1 results' do
|
17
|
+
before(:each) do
|
18
|
+
@paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :limit => 6)
|
40
19
|
end
|
20
|
+
it 'should have next' do
|
21
|
+
@paginator.should be_has_next
|
22
|
+
end
|
23
|
+
|
41
24
|
end
|
25
|
+
it 'should not have next when there are fewer results' do
|
26
|
+
paginator = Blacklight::Solr::FacetPaginator.new(@six_facet_values, :offset => 0, :limit => @limit)
|
42
27
|
|
43
|
-
|
44
|
-
subject { Blacklight::Solr::FacetPaginator.new(six_facet_values, offset: 0, limit: limit) }
|
45
|
-
it { should be_first_page }
|
46
|
-
it { should be_last_page }
|
28
|
+
paginator.should_not be_has_next
|
47
29
|
end
|
30
|
+
context 'when offset is greater than 0' do
|
31
|
+
before(:each) do
|
32
|
+
@offset = 100
|
33
|
+
@paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => @offset, :limit => @limit)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have previous' do
|
37
|
+
@paginator.should be_has_previous
|
38
|
+
end
|
48
39
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
let(:paginator) { Blacklight::Solr::FacetPaginator.new(seven_facet_values, offset: 100, limit: limit, sort: 'index') }
|
40
|
+
end
|
41
|
+
it 'should not have previous when offset is 0' do
|
42
|
+
paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 0, :limit => @limit)
|
53
43
|
|
54
|
-
|
55
|
-
|
44
|
+
paginator.should_not be_has_previous
|
45
|
+
end
|
46
|
+
it 'should know a manually set sort, and produce proper sort url' do
|
47
|
+
paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 100, :limit => @limit, :sort => 'index')
|
56
48
|
|
57
|
-
|
49
|
+
paginator.sort.should == 'index'
|
50
|
+
|
51
|
+
click_params = paginator.params_for_resort_url('count', {})
|
58
52
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
53
|
+
click_params[ @sort_key ].should == 'count'
|
54
|
+
click_params[ @page_key ].should be_nil
|
62
55
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
56
|
+
it 'should limit items to limit, if limit is smaller than items.length' do
|
57
|
+
paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 100, :limit => 6, :sort => 'index')
|
58
|
+
paginator.items.length.should == 6
|
59
|
+
end
|
60
|
+
it 'should return all items when limit is greater than items.length' do
|
61
|
+
paginator = Blacklight::Solr::FacetPaginator.new(@six_facet_values, :offset => 100, :limit => 6, :sort => 'index')
|
62
|
+
paginator.items.length.should == 6
|
63
|
+
end
|
64
|
+
describe "for a nil :limit" do
|
65
|
+
before(:all) do
|
66
|
+
@paginator = Blacklight::Solr::FacetPaginator.new(@seven_facet_values, :offset => 100, :limit => nil, :sort => 'index')
|
67
|
+
end
|
68
|
+
it 'should return all items' do
|
69
|
+
@paginator.items.should == @seven_facet_values
|
70
|
+
end
|
71
|
+
it 'should not has_next?' do
|
72
|
+
@paginator.should_not be_has_next
|
73
|
+
end
|
74
|
+
it 'should not has_previous?' do
|
75
|
+
@paginator.should_not be_has_previous
|
68
76
|
end
|
69
77
|
end
|
70
|
-
|
78
|
+
|
71
79
|
end
|
@@ -21,12 +21,12 @@ describe Blacklight::SearchFields do
|
|
21
21
|
|
22
22
|
before(:each) do
|
23
23
|
@search_field_obj = MockConfig.new
|
24
|
-
|
24
|
+
@search_field_obj.stub(:blacklight_config).and_return(@config)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should return search field list with calculated :label when needed" do
|
28
28
|
@search_field_obj.search_field_list.each do |hash|
|
29
|
-
|
29
|
+
hash.label.should_not be_blank
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -42,30 +42,30 @@ describe Blacklight::SearchFields do
|
|
42
42
|
argument = select_arguments[index]
|
43
43
|
config_hash = @search_field_obj.search_field_list[index]
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
argument.length.should == 2
|
46
|
+
argument[0].should == config_hash.label
|
47
|
+
argument[1].should == config_hash.key
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should not include fields in select if :display_in_simple_search=>false" do
|
52
52
|
select_arguments = @search_field_obj.search_field_options_for_select
|
53
53
|
|
54
|
-
|
54
|
+
select_arguments.should_not include(["No Display", "no_display"])
|
55
55
|
end
|
56
56
|
|
57
57
|
|
58
58
|
|
59
59
|
it "should lookup field definitions by key" do
|
60
|
-
|
60
|
+
@search_field_obj.search_field_def_for_key("title").key.should == "title"
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should find label by key" do
|
64
|
-
|
64
|
+
@search_field_obj.label_for_search_field("title").should == "Title"
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should supply default label for key not found" do
|
68
|
-
|
68
|
+
@search_field_obj.label_for_search_field("non_existent_key").should == "Keyword"
|
69
69
|
end
|
70
70
|
|
71
71
|
describe "for unspecified :key" do
|
@@ -73,10 +73,10 @@ describe Blacklight::SearchFields do
|
|
73
73
|
@bad_config = MockConfig.new
|
74
74
|
end
|
75
75
|
it "should raise exception on #search_field_list" do
|
76
|
-
|
76
|
+
lambda { @bad_config.stub(:blacklight_config).and_return(Blacklight::Configuration.new { |config|
|
77
77
|
config.add_search_field :label => 'All Fields', :qt => 'all_fields'
|
78
78
|
config.add_search_field 'title', :qt => 'title_search'
|
79
|
-
}) }.
|
79
|
+
}) }.should raise_error
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -85,11 +85,11 @@ describe Blacklight::SearchFields do
|
|
85
85
|
@bad_config = MockConfig.new
|
86
86
|
end
|
87
87
|
it "should raise on #search_field_list" do
|
88
|
-
|
88
|
+
lambda { @bad_config.stub(:blacklight_config).and_return(Blacklight::Configuration.new { |config|
|
89
89
|
config.add_search_field 'my_key', :label => 'All Fields'
|
90
90
|
config.add_search_field 'my_key', :label => 'title'
|
91
91
|
|
92
|
-
}) }.
|
92
|
+
}) }.should raise_error
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -1,11 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
-
require 'marc'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
=begin
|
9
4
|
# check the methods that do solr requests. Note that we are not testing if
|
10
5
|
# solr gives "correct" responses, as that's out of scope (it's a part of
|
11
6
|
# testing the solr code itself). We *are* testing if blacklight code sends
|
@@ -13,7 +8,7 @@ require 'marc'
|
|
13
8
|
# do we get data back from solr (i.e. did we properly configure blacklight code
|
14
9
|
# to talk with solr and get results)? when we do a document request, does
|
15
10
|
# blacklight code get a single document returned?)
|
16
|
-
|
11
|
+
#
|
17
12
|
describe 'Blacklight::SolrHelper' do
|
18
13
|
|
19
14
|
# SolrHelper is a controller layer mixin, which depends
|
@@ -26,15 +21,13 @@ describe 'Blacklight::SolrHelper' do
|
|
26
21
|
def blacklight_config
|
27
22
|
@config ||= CatalogController.blacklight_config
|
28
23
|
end
|
29
|
-
|
24
|
+
|
30
25
|
def blacklight_config=(config)
|
31
26
|
@config = config
|
32
27
|
end
|
33
28
|
|
34
29
|
def blacklight_solr
|
35
|
-
|
36
|
-
Blacklight.solr
|
37
|
-
}
|
30
|
+
Blacklight.solr
|
38
31
|
end
|
39
32
|
|
40
33
|
include Blacklight::SolrHelper
|
@@ -51,25 +44,25 @@ describe 'Blacklight::SolrHelper' do
|
|
51
44
|
@subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"rows"=>"10", :"q"=>"wome"}
|
52
45
|
end
|
53
46
|
|
54
|
-
|
47
|
+
|
55
48
|
|
56
49
|
# SPECS for actual search parameter generation
|
57
50
|
describe "solr_search_params" do
|
58
51
|
it "allows customization of solr_search_params_logic" do
|
59
52
|
# Normally you'd include a new module into (eg) your CatalogController
|
60
|
-
# but a sub-class defininig it directly is simpler for test.
|
53
|
+
# but a sub-class defininig it directly is simpler for test.
|
61
54
|
def add_foo_to_solr_params(solr_params, user_params)
|
62
|
-
solr_params[:
|
55
|
+
solr_params[:wt] = "TESTING"
|
63
56
|
end
|
64
|
-
|
65
|
-
|
57
|
+
|
58
|
+
|
66
59
|
self.solr_search_params_logic += [:add_foo_to_solr_params]
|
67
|
-
|
68
|
-
|
69
|
-
|
60
|
+
|
61
|
+
|
62
|
+
self.solr_search_params[:wt].should == "TESTING"
|
70
63
|
end
|
71
|
-
|
72
|
-
|
64
|
+
|
65
|
+
|
73
66
|
describe 'for an entirely empty search' do
|
74
67
|
def params
|
75
68
|
{}
|
@@ -78,40 +71,40 @@ describe 'Blacklight::SolrHelper' do
|
|
78
71
|
@produced_params = self.solr_search_params
|
79
72
|
end
|
80
73
|
it 'should not have a q param' do
|
81
|
-
|
82
|
-
|
74
|
+
@produced_params[:q].should be_nil
|
75
|
+
@produced_params["spellcheck.q"].should be_nil
|
83
76
|
end
|
84
77
|
it 'should have default rows' do
|
85
|
-
|
78
|
+
@produced_params[:rows].should == 10
|
86
79
|
end
|
87
80
|
it 'should have default facet fields' do
|
88
81
|
# remove local params from the facet.field
|
89
|
-
|
82
|
+
@produced_params[:"facet.field"].map { |x| x.gsub(/\{![^}]+\}/, '') }.should == blacklight_config.facet_fields_to_add_to_solr
|
90
83
|
end
|
91
|
-
|
84
|
+
|
92
85
|
it "should have default qt" do
|
93
|
-
|
86
|
+
@produced_params[:qt].should == "search"
|
94
87
|
end
|
95
88
|
it "should have no fq" do
|
96
|
-
|
97
|
-
|
89
|
+
@produced_params[:phrase_filters].should be_blank
|
90
|
+
@produced_params[:fq].should be_blank
|
98
91
|
end
|
99
92
|
end
|
100
93
|
|
101
94
|
|
102
|
-
describe "for an empty string search" do
|
103
|
-
it "should return empty string q in solr parameters" do
|
95
|
+
describe "for an empty string search" do
|
96
|
+
it "should return empty string q in solr parameters" do
|
104
97
|
solr_params = solr_search_params(:q => "")
|
105
|
-
|
106
|
-
|
98
|
+
solr_params[:q].should == ""
|
99
|
+
solr_params["spellcheck.q"].should == ""
|
107
100
|
end
|
108
101
|
end
|
109
102
|
|
110
|
-
describe "for request params also passed in as argument" do
|
111
|
-
it "should only have one 'q'
|
112
|
-
solr_params = solr_search_params( :q => "some query" )
|
113
|
-
|
114
|
-
|
103
|
+
describe "for request params also passed in as argument" do
|
104
|
+
it "should only have one value for the key 'q' regardless if a symbol or string" do
|
105
|
+
solr_params = solr_search_params( :q => "some query", 'q' => 'another value' )
|
106
|
+
solr_params[:q].should == 'some query'
|
107
|
+
solr_params['q'].should == 'some query'
|
115
108
|
end
|
116
109
|
end
|
117
110
|
|
@@ -121,11 +114,11 @@ describe 'Blacklight::SolrHelper' do
|
|
121
114
|
|
122
115
|
solr_params = solr_search_params(:f => @single_facet)
|
123
116
|
|
124
|
-
|
125
|
-
|
117
|
+
solr_params[:q].should be_blank
|
118
|
+
solr_params["spellcheck.q"].should be_blank
|
126
119
|
|
127
120
|
@single_facet.each_value do |value|
|
128
|
-
|
121
|
+
solr_params[:fq].should include("{!raw f=#{@single_facet.keys[0]}}#{value}")
|
129
122
|
end
|
130
123
|
end
|
131
124
|
end
|
@@ -138,7 +131,7 @@ describe 'Blacklight::SolrHelper' do
|
|
138
131
|
value_list ||= []
|
139
132
|
value_list = [value_list] unless value_list.respond_to? :each
|
140
133
|
value_list.each do |value|
|
141
|
-
|
134
|
+
solr_params[:fq].should include("{!raw f=#{facet_field}}#{value}" )
|
142
135
|
end
|
143
136
|
end
|
144
137
|
|
@@ -153,10 +146,10 @@ describe 'Blacklight::SolrHelper' do
|
|
153
146
|
value_list ||= []
|
154
147
|
value_list = [value_list] unless value_list.respond_to? :each
|
155
148
|
value_list.each do |value|
|
156
|
-
|
149
|
+
solr_params[:fq].should include("{!raw f=#{facet_field}}#{value}" )
|
157
150
|
end
|
158
151
|
end
|
159
|
-
|
152
|
+
solr_params[:q].should == @mult_word_query
|
160
153
|
end
|
161
154
|
end
|
162
155
|
|
@@ -167,91 +160,80 @@ describe 'Blacklight::SolrHelper' do
|
|
167
160
|
end
|
168
161
|
|
169
162
|
it "should use the raw handler for strings" do
|
170
|
-
|
163
|
+
facet_value_to_fq_string("facet_name", "my value").should == "{!raw f=facet_name}my value"
|
171
164
|
end
|
172
165
|
|
173
166
|
it "should pass booleans through" do
|
174
|
-
|
167
|
+
facet_value_to_fq_string("facet_name", true).should == "facet_name:true"
|
175
168
|
end
|
176
169
|
|
177
170
|
it "should pass boolean-like strings through" do
|
178
|
-
|
171
|
+
facet_value_to_fq_string("facet_name", "true").should == "facet_name:true"
|
179
172
|
end
|
180
173
|
|
181
174
|
it "should pass integers through" do
|
182
|
-
|
175
|
+
facet_value_to_fq_string("facet_name", 1).should == "facet_name:1"
|
183
176
|
end
|
184
177
|
|
185
178
|
it "should pass integer-like strings through" do
|
186
|
-
|
179
|
+
facet_value_to_fq_string("facet_name", "1").should == "facet_name:1"
|
187
180
|
end
|
188
181
|
|
189
182
|
it "should pass floats through" do
|
190
|
-
|
183
|
+
facet_value_to_fq_string("facet_name", 1.11).should == "facet_name:1.11"
|
191
184
|
end
|
192
185
|
|
193
186
|
it "should pass floats through" do
|
194
|
-
|
187
|
+
facet_value_to_fq_string("facet_name", "1.11").should == "facet_name:1.11"
|
195
188
|
end
|
196
189
|
|
197
190
|
it "should pass date-type fields through" do
|
198
|
-
|
199
|
-
|
200
|
-
expect(facet_value_to_fq_string("facet_name", "2012-01-01")).to eq "facet_name:2012\\-01\\-01"
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should escape datetime-type fields" do
|
204
|
-
allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(:date => true, :query => nil, :tag => nil))
|
191
|
+
blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(double(:date => true, :query => nil, :tag => nil))
|
205
192
|
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should format Date objects correctly" do
|
210
|
-
allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(:date => nil, :query => nil, :tag => nil))
|
211
|
-
d = DateTime.parse("2003-04-09T00:00:00")
|
212
|
-
expect(facet_value_to_fq_string("facet_name", d)).to eq "facet_name:2003\\-04\\-09T00\\:00\\:00Z"
|
193
|
+
facet_value_to_fq_string("facet_name", "2012-01-01").should == "facet_name:2012-01-01"
|
213
194
|
end
|
214
195
|
|
215
196
|
it "should handle range requests" do
|
216
|
-
|
197
|
+
facet_value_to_fq_string("facet_name", 1..5).should == "facet_name:[1 TO 5]"
|
217
198
|
end
|
218
199
|
|
219
200
|
it "should add tag local parameters" do
|
220
|
-
|
201
|
+
blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(double(:query => nil, :tag => 'asdf', :date => nil))
|
221
202
|
|
222
|
-
|
223
|
-
|
203
|
+
facet_value_to_fq_string("facet_name", true).should == "{!tag=asdf}facet_name:true"
|
204
|
+
facet_value_to_fq_string("facet_name", "my value").should == "{!raw f=facet_name tag=asdf}my value"
|
224
205
|
end
|
225
206
|
end
|
226
207
|
|
227
208
|
describe "solr parameters for a field search from config (subject)" do
|
228
|
-
|
229
|
-
|
230
|
-
end
|
209
|
+
let(:solr_params) { solr_search_params @subject_search_params }
|
210
|
+
|
231
211
|
it "should look up qt from field definition" do
|
232
|
-
|
212
|
+
solr_params[:qt].should == "search"
|
233
213
|
end
|
234
214
|
it "should not include weird keys not in field definition" do
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
215
|
+
solr_params.to_hash.tap do |h|
|
216
|
+
h[:phrase_filters].should be_nil
|
217
|
+
h[:fq].should be_nil
|
218
|
+
h[:commit].should be_nil
|
219
|
+
h[:action].should be_nil
|
220
|
+
h[:controller].should be_nil
|
221
|
+
end
|
240
222
|
end
|
241
223
|
it "should include proper 'q', possibly with LocalParams" do
|
242
|
-
|
224
|
+
solr_params[:q].should match(/(\{[^}]+\})?wome/)
|
243
225
|
end
|
244
226
|
it "should include proper 'q' when LocalParams are used" do
|
245
|
-
if
|
246
|
-
|
227
|
+
if solr_params[:q] =~ /\{[^}]+\}/
|
228
|
+
solr_params[:q].should match(/\{[^}]+\}wome/)
|
247
229
|
end
|
248
230
|
end
|
249
231
|
it "should include spellcheck.q, without LocalParams" do
|
250
|
-
|
232
|
+
solr_params["spellcheck.q"].should == "wome"
|
251
233
|
end
|
252
234
|
|
253
235
|
it "should include spellcheck.dictionary from field def solr_parameters" do
|
254
|
-
|
236
|
+
solr_params[:"spellcheck.dictionary"].should == "subject"
|
255
237
|
end
|
256
238
|
it "should add on :solr_local_parameters using Solr LocalParams style" do
|
257
239
|
params = solr_search_params( @subject_search_params )
|
@@ -260,8 +242,8 @@ describe 'Blacklight::SolrHelper' do
|
|
260
242
|
#the LocalParams are really there
|
261
243
|
params[:q] =~ /^\{!([^}]+)\}/
|
262
244
|
key_value_pairs = $1.split(" ")
|
263
|
-
|
264
|
-
|
245
|
+
key_value_pairs.should include("pf=$subject_pf")
|
246
|
+
key_value_pairs.should include("qf=$subject_qf")
|
265
247
|
end
|
266
248
|
end
|
267
249
|
|
@@ -270,18 +252,18 @@ describe 'Blacklight::SolrHelper' do
|
|
270
252
|
def params
|
271
253
|
super.merge(:qt => "overridden")
|
272
254
|
end
|
273
|
-
|
274
|
-
|
255
|
+
|
256
|
+
solr_search_params[:qt].should == "overridden"
|
275
257
|
end
|
276
258
|
end
|
277
259
|
|
278
260
|
describe "converts a String fq into an Array" do
|
279
261
|
it "should return the correct overriden parameter" do
|
280
262
|
solr_parameters = {:fq => 'a string' }
|
281
|
-
|
263
|
+
|
282
264
|
add_facet_fq_to_solr(solr_parameters, {})
|
283
265
|
|
284
|
-
|
266
|
+
solr_parameters[:fq].should be_a_kind_of Array
|
285
267
|
end
|
286
268
|
end
|
287
269
|
|
@@ -300,48 +282,48 @@ describe 'Blacklight::SolrHelper' do
|
|
300
282
|
|
301
283
|
it "should return the correct solr parameters" do
|
302
284
|
|
303
|
-
solr_parameters =
|
304
|
-
|
285
|
+
solr_parameters = Blacklight::Solr::Request.new
|
286
|
+
|
305
287
|
add_facetting_to_solr(solr_parameters, {})
|
306
288
|
|
307
|
-
expect(solr_parameters[:facet]).to
|
289
|
+
expect(solr_parameters[:facet]).to be_true
|
308
290
|
|
309
|
-
|
310
|
-
|
291
|
+
solr_parameters[:'facet.field'].should include('test_field')
|
292
|
+
solr_parameters[:'f.test_field.facet.sort'].should == 'count'
|
311
293
|
end
|
312
294
|
|
313
295
|
it "should add facet exclusions" do
|
314
|
-
solr_parameters =
|
296
|
+
solr_parameters = Blacklight::Solr::Request.new
|
315
297
|
|
316
298
|
add_facetting_to_solr(solr_parameters, {})
|
317
299
|
|
318
|
-
|
319
|
-
|
300
|
+
solr_parameters[:'facet.query'].should include('{!ex=xyz}some:query')
|
301
|
+
solr_parameters[:'facet.pivot'].should include('{!ex=xyz}a,b')
|
320
302
|
end
|
321
303
|
end
|
322
304
|
|
323
305
|
describe "with a complex parameter environment" do
|
324
|
-
def blacklight_config
|
306
|
+
def blacklight_config
|
325
307
|
config = Blacklight::Configuration.new
|
326
308
|
config.add_search_field("test_field",
|
327
|
-
:display_label => "Test",
|
328
|
-
:key=>"test_field",
|
309
|
+
:display_label => "Test",
|
310
|
+
:key=>"test_field",
|
329
311
|
:solr_parameters => {:qf => "fieldOne^2.3 fieldTwo fieldThree^0.4", :pf => "", :spellcheck => 'false', :rows => "55", :sort => "request_params_sort" }
|
330
312
|
)
|
331
313
|
return config
|
332
314
|
end
|
333
|
-
def params
|
315
|
+
def params
|
334
316
|
{:search_field => "test_field", :q => "test query", "facet.field" => "extra_facet"}
|
335
317
|
end
|
336
|
-
|
318
|
+
|
337
319
|
it "should merge parameters from search_field definition" do
|
338
320
|
solr_params = solr_search_params
|
339
|
-
|
340
|
-
|
341
|
-
|
321
|
+
|
322
|
+
solr_params[:qf].should == "fieldOne^2.3 fieldTwo fieldThree^0.4"
|
323
|
+
solr_params[:spellcheck].should == 'false'
|
342
324
|
end
|
343
325
|
it "should merge empty string parameters from search_field definition" do
|
344
|
-
|
326
|
+
solr_search_params[:pf].should == ""
|
345
327
|
end
|
346
328
|
|
347
329
|
describe "should respect proper precedence of settings, " do
|
@@ -351,53 +333,53 @@ describe 'Blacklight::SolrHelper' do
|
|
351
333
|
|
352
334
|
|
353
335
|
it "should not put :search_field in produced params" do
|
354
|
-
|
336
|
+
@produced_params[:search_field].should be_nil
|
355
337
|
end
|
356
338
|
|
357
339
|
it "should fall through to BL general defaults for qt not otherwise specified " do
|
358
|
-
|
340
|
+
@produced_params[:qt].should == blacklight_config[:default_solr_params][:qt]
|
359
341
|
end
|
360
342
|
|
361
343
|
it "should take rows from search field definition where specified" do
|
362
|
-
|
344
|
+
@produced_params[:rows].should == "55"
|
363
345
|
end
|
364
346
|
|
365
347
|
it "should take q from request params" do
|
366
|
-
|
348
|
+
@produced_params[:q].should == "test query"
|
367
349
|
end
|
368
350
|
|
369
351
|
it "should add in extra facet.field from params" do
|
370
|
-
|
352
|
+
@produced_params[:"facet.field"].should include("extra_facet")
|
371
353
|
end
|
372
354
|
|
373
355
|
end
|
374
356
|
end
|
375
357
|
|
376
358
|
describe "sorting" do
|
377
|
-
|
378
|
-
it "should send the default sort parameter to solr" do
|
379
|
-
|
359
|
+
|
360
|
+
it "should send the default sort parameter to solr" do
|
361
|
+
solr_search_params[:sort].should == 'score desc, pub_date_sort desc, title_sort asc'
|
380
362
|
end
|
381
363
|
|
382
364
|
it "should not send a sort parameter to solr if the sort value is blank" do
|
383
|
-
def blacklight_config
|
365
|
+
def blacklight_config
|
384
366
|
config = Blacklight::Configuration.new
|
385
367
|
config.add_sort_field('', :label => 'test')
|
386
368
|
return config
|
387
369
|
end
|
388
370
|
|
389
371
|
produced_params = solr_search_params
|
390
|
-
|
372
|
+
produced_params.should_not have_key(:sort)
|
391
373
|
end
|
392
374
|
|
393
375
|
it "should pass through user sort parameters" do
|
394
376
|
produced_params = solr_search_params( :sort => 'solr_test_field desc' )
|
395
|
-
|
377
|
+
produced_params[:sort].should == 'solr_test_field desc'
|
396
378
|
end
|
397
379
|
end
|
398
380
|
|
399
381
|
describe "for :solr_local_parameters config" do
|
400
|
-
def blacklight_config
|
382
|
+
def blacklight_config
|
401
383
|
config = Blacklight::Configuration.new
|
402
384
|
config.add_search_field(
|
403
385
|
"custom_author_key",
|
@@ -416,45 +398,45 @@ describe 'Blacklight::SolrHelper' do
|
|
416
398
|
)
|
417
399
|
return config
|
418
400
|
end
|
419
|
-
|
420
|
-
def params
|
401
|
+
|
402
|
+
def params
|
421
403
|
{:search_field => "custom_author_key", :q => "query"}
|
422
404
|
end
|
423
|
-
|
405
|
+
|
424
406
|
before do
|
425
407
|
@result = solr_search_params
|
426
408
|
end
|
427
409
|
|
428
410
|
it "should pass through ordinary params" do
|
429
|
-
|
430
|
-
|
431
|
-
|
411
|
+
@result[:qt].should == "author_qt"
|
412
|
+
@result[:ps].should == "2"
|
413
|
+
@result[:qf].should == "someField^1000"
|
432
414
|
end
|
433
415
|
|
434
416
|
it "should include include local params with escaping" do
|
435
|
-
|
436
|
-
|
437
|
-
|
417
|
+
@result[:q].should include('qf=$author_qf')
|
418
|
+
@result[:q].should include('pf=\'you\\\'ll have \\" to escape this\'')
|
419
|
+
@result[:q].should include('pf2=$pf2_do_not_escape_or_quote')
|
438
420
|
end
|
439
421
|
end
|
440
|
-
|
422
|
+
|
441
423
|
describe "mapping facet.field" do
|
442
424
|
it "should add single additional facet.field from app" do
|
443
425
|
solr_params = solr_search_params( "facet.field" => "additional_facet" )
|
444
|
-
|
445
|
-
|
426
|
+
solr_params[:"facet.field"].should include("additional_facet")
|
427
|
+
solr_params[:"facet.field"].length.should > 1
|
446
428
|
end
|
447
429
|
it "should map multiple facet.field to additional facet.field" do
|
448
430
|
solr_params = solr_search_params( "facet.field" => ["add_facet1", "add_facet2"] )
|
449
|
-
|
450
|
-
|
451
|
-
|
431
|
+
solr_params[:"facet.field"].should include("add_facet1")
|
432
|
+
solr_params[:"facet.field"].should include("add_facet2")
|
433
|
+
solr_params[:"facet.field"].length.should > 2
|
452
434
|
end
|
453
435
|
it "should map facets[fields][] to additional facet.field" do
|
454
436
|
solr_params = solr_search_params( "facets" => ["add_facet1", "add_facet2"] )
|
455
|
-
|
456
|
-
|
457
|
-
|
437
|
+
solr_params[:"facet.field"].should include("add_facet1")
|
438
|
+
solr_params[:"facet.field"].should include("add_facet2")
|
439
|
+
solr_params[:"facet.field"].length.should > 2
|
458
440
|
end
|
459
441
|
end
|
460
442
|
|
@@ -476,21 +458,21 @@ describe 'Blacklight::SolrHelper' do
|
|
476
458
|
end
|
477
459
|
end
|
478
460
|
it 'sets rows to 0' do
|
479
|
-
|
461
|
+
@generated_solr_facet_params[:rows].should == 0
|
480
462
|
end
|
481
463
|
it 'sets facets requested to facet_field argument' do
|
482
|
-
|
464
|
+
@generated_solr_facet_params["facet.field".to_sym].should == @facet_field
|
483
465
|
end
|
484
466
|
it 'defaults offset to 0' do
|
485
|
-
|
467
|
+
@generated_solr_facet_params[:"f.#{@facet_field}.facet.offset"].should == 0
|
486
468
|
end
|
487
469
|
it 'uses offset manually set, and converts it to an integer' do
|
488
470
|
solr_params = solr_facet_params(@facet_field, @page_key => 2)
|
489
|
-
|
471
|
+
solr_params[:"f.#{@facet_field}.facet.offset"].should == 20
|
490
472
|
end
|
491
473
|
it 'defaults limit to 20' do
|
492
474
|
solr_params = solr_facet_params(@facet_field)
|
493
|
-
|
475
|
+
solr_params[:"f.#{@facet_field}.facet.limit"].should == 21
|
494
476
|
end
|
495
477
|
|
496
478
|
describe 'if facet_list_limit is defined in controller' do
|
@@ -499,29 +481,29 @@ describe 'Blacklight::SolrHelper' do
|
|
499
481
|
end
|
500
482
|
it 'uses controller method for limit' do
|
501
483
|
solr_params = solr_facet_params(@facet_field)
|
502
|
-
|
484
|
+
solr_params[:"f.#{@facet_field}.facet.limit"].should == 1001
|
503
485
|
end
|
504
486
|
|
505
487
|
it 'uses controller method for limit when a ordinary limit is set' do
|
506
488
|
solr_params = solr_facet_params(@facet_field)
|
507
|
-
|
489
|
+
solr_params[:"f.#{@facet_field}.facet.limit"].should == 1001
|
508
490
|
end
|
509
491
|
end
|
510
492
|
|
511
493
|
it 'uses the default sort' do
|
512
494
|
solr_params = solr_facet_params(@facet_field)
|
513
|
-
|
495
|
+
solr_params[:"f.#{@facet_field}.facet.sort"].should be_blank
|
514
496
|
end
|
515
497
|
|
516
498
|
it "uses the field-specific sort" do
|
517
499
|
@facet_field = 'format_ordered'
|
518
500
|
solr_params = solr_facet_params(@facet_field)
|
519
|
-
|
501
|
+
solr_params[:"f.#{@facet_field}.facet.sort"].should == :count
|
520
502
|
end
|
521
503
|
|
522
504
|
it 'uses sort provided in the parameters' do
|
523
505
|
solr_params = solr_facet_params(@facet_field, @sort_key => "index")
|
524
|
-
|
506
|
+
solr_params[:"f.#{@facet_field}.facet.sort"].should == 'index'
|
525
507
|
end
|
526
508
|
it "comes up with the same params as #solr_search_params to constrain context for facet list" do
|
527
509
|
search_params = {:q => 'tibetan history', :f=> {:format=>'Book', :language_facet=>'Tibetan'}}
|
@@ -531,41 +513,41 @@ describe 'Blacklight::SolrHelper' do
|
|
531
513
|
solr_search_params.each_pair do |key, value|
|
532
514
|
# The specific params used for fetching the facet list we
|
533
515
|
# don't care about.
|
534
|
-
next if [
|
516
|
+
next if ['facets', "facet.field", 'rows', 'facet.limit', 'facet.offset', 'facet.sort'].include?(key)
|
535
517
|
# Everything else should match
|
536
|
-
|
518
|
+
solr_facet_params[key].should == value
|
537
519
|
end
|
538
520
|
|
539
521
|
end
|
540
522
|
end
|
541
|
-
describe "for facet limit parameters config ed" do
|
523
|
+
describe "for facet limit parameters config ed" do
|
542
524
|
def params
|
543
525
|
{:search_field => "test_field", :q => "test query"}
|
544
526
|
end
|
545
|
-
|
546
|
-
|
547
|
-
before do
|
527
|
+
|
528
|
+
|
529
|
+
before do
|
548
530
|
@generated_params = solr_search_params
|
549
531
|
end
|
550
|
-
|
532
|
+
|
551
533
|
it "should include specifically configged facet limits +1" do
|
552
|
-
|
534
|
+
@generated_params[:"f.subject_topic_facet.facet.limit"].should == 21
|
553
535
|
end
|
554
536
|
it "should not include a facet limit for a nil key in hash" do
|
555
|
-
|
556
|
-
|
537
|
+
@generated_params.should_not have_key(:"f.format.facet.limit")
|
538
|
+
@generated_params.should_not have_key(:"facet.limit")
|
557
539
|
end
|
558
540
|
end
|
559
|
-
|
541
|
+
|
560
542
|
describe "get_facet_pagination", :integration => true do
|
561
543
|
before(:each) do
|
562
544
|
@facet_paginator = get_facet_pagination(@facet_field)
|
563
545
|
end
|
564
546
|
it 'should return a facet paginator' do
|
565
|
-
|
547
|
+
@facet_paginator.should be_a_kind_of(Blacklight::Solr::FacetPaginator)
|
566
548
|
end
|
567
549
|
it 'with a limit set' do
|
568
|
-
|
550
|
+
@facet_paginator.limit.should_not be_nil
|
569
551
|
end
|
570
552
|
end
|
571
553
|
|
@@ -574,23 +556,23 @@ describe 'Blacklight::SolrHelper' do
|
|
574
556
|
|
575
557
|
describe 'for a sample query returning results' do
|
576
558
|
|
577
|
-
before(:all) do
|
559
|
+
before(:all) do
|
578
560
|
(@solr_response, @document_list) = get_search_results(:q => @all_docs_query)
|
579
561
|
end
|
580
562
|
|
581
563
|
it "should use the configured request handler " do
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
564
|
+
blacklight_config.stub(:default_solr_params).and_return({:qt => 'custom_request_handler'})
|
565
|
+
Blacklight.solr.should_receive(:send_and_receive) do |path, params|
|
566
|
+
path.should == 'select'
|
567
|
+
params[:params][:'facet.field'].should == ["format", "{!ex=pub_date_single}pub_date", "subject_topic_facet", "language_facet", "lc_1letter_facet", "subject_geo_facet", "subject_era_facet"]
|
568
|
+
params[:params][:"facet.query"].should == ["pub_date:[#{5.years.ago.year} TO *]", "pub_date:[#{10.years.ago.year} TO *]", "pub_date:[#{25.years.ago.year} TO *]"]
|
569
|
+
params[:params].should include(:rows => 10, :qt=>"custom_request_handler", :q=>"", "spellcheck.q"=>"", :"f.subject_topic_facet.facet.limit"=>21, :sort=>"score desc, pub_date_sort desc, title_sort asc")
|
570
|
+
end.and_return({'response'=>{'docs'=>[]}})
|
589
571
|
get_search_results(:q => @all_docs_query)
|
590
572
|
end
|
591
573
|
|
592
574
|
it 'should have a @response.docs list of the same size as @document_list' do
|
593
|
-
|
575
|
+
@solr_response.docs.length.should == @document_list.length
|
594
576
|
end
|
595
577
|
|
596
578
|
it 'should have @response.docs list representing same documents as SolrDocuments in @document_list' do
|
@@ -598,10 +580,10 @@ describe 'Blacklight::SolrHelper' do
|
|
598
580
|
mash = @solr_response.docs[index]
|
599
581
|
solr_document = @document_list[index]
|
600
582
|
|
601
|
-
|
583
|
+
Set.new(mash.keys).should == Set.new(solr_document.keys)
|
602
584
|
|
603
585
|
mash.each_key do |key|
|
604
|
-
|
586
|
+
mash[key].should == solr_document[key]
|
605
587
|
end
|
606
588
|
end
|
607
589
|
end
|
@@ -644,7 +626,7 @@ describe 'Blacklight::SolrHelper' do
|
|
644
626
|
describe '#query_solr' do
|
645
627
|
it 'should have results' do
|
646
628
|
solr_response = query_solr(:q => @single_word_query)
|
647
|
-
|
629
|
+
solr_response.docs.size.should > 0
|
648
630
|
end
|
649
631
|
|
650
632
|
end
|
@@ -654,24 +636,24 @@ describe 'Blacklight::SolrHelper' do
|
|
654
636
|
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
655
637
|
result_docs = document_list
|
656
638
|
document = result_docs.first
|
657
|
-
|
658
|
-
|
639
|
+
document.get(blacklight_config.index.show_link).should_not == nil
|
640
|
+
document.get(blacklight_config.index.record_display_type).should_not == nil
|
659
641
|
end
|
660
642
|
end
|
661
643
|
|
662
644
|
|
663
645
|
|
664
646
|
describe "Single Word Query with no Facets" do
|
665
|
-
|
647
|
+
|
666
648
|
it 'should have results' do
|
667
649
|
solr_response = query_solr(:q => @single_word_query)
|
668
|
-
|
650
|
+
solr_response.docs.size.should > 0
|
669
651
|
end
|
670
652
|
|
671
653
|
it 'should have results' do
|
672
654
|
(solr_response, document_list) = get_search_results(:q => @single_word_query)
|
673
|
-
|
674
|
-
|
655
|
+
solr_response.docs.size.should == document_list.size
|
656
|
+
solr_response.docs.size.should > 0
|
675
657
|
end
|
676
658
|
end
|
677
659
|
|
@@ -679,48 +661,48 @@ describe 'Blacklight::SolrHelper' do
|
|
679
661
|
it 'should have results' do
|
680
662
|
|
681
663
|
(solr_response, document_list) = get_search_results(:q => @mult_word_query)
|
682
|
-
|
683
|
-
|
664
|
+
solr_response.docs.size.should == document_list.size
|
665
|
+
solr_response.docs.size.should > 0
|
684
666
|
end
|
685
667
|
end
|
686
668
|
|
687
669
|
describe "One Facet, No Query" do
|
688
670
|
it 'should have results' do
|
689
671
|
(solr_response, document_list) = get_search_results(:f => @single_facet)
|
690
|
-
|
691
|
-
|
672
|
+
solr_response.docs.size.should == document_list.size
|
673
|
+
solr_response.docs.size.should > 0
|
692
674
|
end
|
693
675
|
end
|
694
676
|
|
695
677
|
describe "Mult Facets, No Query" do
|
696
678
|
it 'should have results' do
|
697
679
|
(solr_response, document_list) = get_search_results(:f => @multi_facets)
|
698
|
-
|
699
|
-
|
680
|
+
solr_response.docs.size.should == document_list.size
|
681
|
+
solr_response.docs.size.should > 0
|
700
682
|
end
|
701
683
|
end
|
702
684
|
|
703
685
|
describe "Single Word Query with One Facet" do
|
704
686
|
it 'should have results' do
|
705
687
|
(solr_response, document_list) = get_search_results(:q => @single_word_query, :f => @single_facet)
|
706
|
-
|
707
|
-
|
688
|
+
solr_response.docs.size.should == document_list.size
|
689
|
+
solr_response.docs.size.should > 0
|
708
690
|
end
|
709
691
|
end
|
710
692
|
|
711
693
|
describe "Multiple Words Query with Multiple Facets" do
|
712
694
|
it 'should have results' do
|
713
695
|
(solr_response, document_list) = get_search_results(:q => @mult_word_query, :f => @multi_facets)
|
714
|
-
|
715
|
-
|
696
|
+
solr_response.docs.size.should == document_list.size
|
697
|
+
solr_response.docs.size.should > 0
|
716
698
|
end
|
717
699
|
end
|
718
700
|
|
719
701
|
describe "for All Docs Query and One Facet" do
|
720
702
|
it 'should have results' do
|
721
703
|
(solr_response, document_list) = get_search_results(:q => @all_docs_query, :f => @single_facet)
|
722
|
-
|
723
|
-
|
704
|
+
solr_response.docs.size.should == document_list.size
|
705
|
+
solr_response.docs.size.should > 0
|
724
706
|
end
|
725
707
|
# TODO: check that number of these results < number of results for all docs query
|
726
708
|
# BUT can't: num docs isn't total, it's the num docs in the single SOLR response (e.g. 10)
|
@@ -729,24 +711,24 @@ describe 'Blacklight::SolrHelper' do
|
|
729
711
|
describe "for Query Without Results and No Facet" do
|
730
712
|
it 'should have no results and not raise error' do
|
731
713
|
(solr_response, document_list) = get_search_results(:q => @no_docs_query)
|
732
|
-
|
733
|
-
|
714
|
+
solr_response.docs.size.should == document_list.size
|
715
|
+
solr_response.docs.size.should == 0
|
734
716
|
end
|
735
717
|
end
|
736
718
|
|
737
719
|
describe "for Query Without Results and One Facet" do
|
738
720
|
it 'should have no results and not raise error' do
|
739
721
|
(solr_response, document_list) = get_search_results(:q => @no_docs_query, :f => @single_facet)
|
740
|
-
|
741
|
-
|
722
|
+
solr_response.docs.size.should == document_list.size
|
723
|
+
solr_response.docs.size.should == 0
|
742
724
|
end
|
743
725
|
end
|
744
726
|
|
745
727
|
describe "for All Docs Query and Bad Facet" do
|
746
728
|
it 'should have no results and not raise error' do
|
747
729
|
(solr_response, document_list) = get_search_results(:q => @all_docs_query, :f => @bad_facet)
|
748
|
-
|
749
|
-
|
730
|
+
solr_response.docs.size.should == document_list.size
|
731
|
+
solr_response.docs.size.should == 0
|
750
732
|
end
|
751
733
|
end
|
752
734
|
|
@@ -765,16 +747,16 @@ describe 'Blacklight::SolrHelper' do
|
|
765
747
|
end
|
766
748
|
|
767
749
|
it 'should have more than one facet' do
|
768
|
-
|
750
|
+
@facets.size.should > 1
|
769
751
|
end
|
770
|
-
it 'should have all facets specified in initializer' do
|
752
|
+
it 'should have all facets specified in initializer' do
|
771
753
|
blacklight_config.facet_fields_to_add_to_solr.each do |field|
|
772
|
-
|
754
|
+
@facets.find {|f| f.name == field}.should_not be_nil
|
773
755
|
end
|
774
756
|
end
|
775
757
|
it 'should have at least one value for each facet' do
|
776
758
|
@facets.each do |facet|
|
777
|
-
|
759
|
+
facet.items.size.should > 0
|
778
760
|
end
|
779
761
|
end
|
780
762
|
it 'should have multiple values for at least one facet' do
|
@@ -785,7 +767,7 @@ describe 'Blacklight::SolrHelper' do
|
|
785
767
|
break
|
786
768
|
end
|
787
769
|
end
|
788
|
-
|
770
|
+
has_mult_values.should == true
|
789
771
|
end
|
790
772
|
it 'should have all value counts > 0' do
|
791
773
|
@facets.each do |facet|
|
@@ -802,58 +784,58 @@ describe 'Blacklight::SolrHelper' do
|
|
802
784
|
|
803
785
|
it 'should start with first results by default' do
|
804
786
|
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
805
|
-
|
787
|
+
solr_response.params[:start].to_i.should == 0
|
806
788
|
end
|
807
789
|
it 'should have number of results (per page) set in initializer, by default' do
|
808
790
|
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
809
|
-
|
810
|
-
|
791
|
+
solr_response.docs.size.should == document_list.size
|
792
|
+
solr_response.docs.size.should == blacklight_config[:default_solr_params][:rows]
|
811
793
|
end
|
812
794
|
|
813
795
|
it 'should get number of results per page requested' do
|
814
796
|
num_results = 3 # non-default value
|
815
797
|
(solr_response1, document_list1) = get_search_results(:q => @all_docs_query, :per_page => num_results)
|
816
|
-
|
817
|
-
|
798
|
+
solr_response1.docs.size.should == document_list1.size
|
799
|
+
solr_response1.docs.size.should == num_results
|
818
800
|
end
|
819
801
|
|
820
802
|
it 'should get number of rows requested' do
|
821
803
|
num_results = 4 # non-default value
|
822
804
|
(solr_response1, document_list1) = get_search_results(:q => @all_docs_query, :rows => num_results)
|
823
|
-
|
824
|
-
|
805
|
+
solr_response1.docs.size.should == document_list1.size
|
806
|
+
solr_response1.docs.size.should == num_results
|
825
807
|
end
|
826
808
|
|
827
809
|
it 'should skip appropriate number of results when requested - default per page' do
|
828
810
|
page = 3
|
829
811
|
(solr_response2, document_list2) = get_search_results(:q => @all_docs_query, :page => page)
|
830
|
-
|
812
|
+
solr_response2.params[:start].to_i.should == blacklight_config[:default_solr_params][:rows] * (page-1)
|
831
813
|
end
|
832
814
|
it 'should skip appropriate number of results when requested - non-default per page' do
|
833
815
|
page = 3
|
834
816
|
num_results = 3
|
835
817
|
(solr_response2a, document_list2a) = get_search_results(:q => @all_docs_query, :per_page => num_results, :page => page)
|
836
|
-
|
818
|
+
solr_response2a.params[:start].to_i.should == num_results * (page-1)
|
837
819
|
end
|
838
820
|
|
839
821
|
it 'should have no results when prompted for page after last result' do
|
840
822
|
big = 5000
|
841
823
|
(solr_response3, document_list3) = get_search_results(:q => @all_docs_query, :rows => big, :page => big)
|
842
|
-
|
843
|
-
|
824
|
+
solr_response3.docs.size.should == document_list3.size
|
825
|
+
solr_response3.docs.size.should == 0
|
844
826
|
end
|
845
827
|
|
846
828
|
it 'should show first results when prompted for page before first result' do
|
847
829
|
# FIXME: should it show first results, or should it throw an error for view to deal w?
|
848
830
|
# Solr throws an error for a negative start value
|
849
831
|
(solr_response4, document_list4) = get_search_results(:q => @all_docs_query, :page => '-1')
|
850
|
-
|
832
|
+
solr_response4.params[:start].to_i.should == 0
|
851
833
|
end
|
852
834
|
it 'should have results available when asked for more than are in response' do
|
853
835
|
big = 5000
|
854
836
|
(solr_response5, document_list5) = get_search_results(:q => @all_docs_query, :rows => big, :page => 1)
|
855
|
-
|
856
|
-
|
837
|
+
solr_response5.docs.size.should == document_list5.size
|
838
|
+
solr_response5.docs.size.should > 0
|
857
839
|
end
|
858
840
|
|
859
841
|
end # page specs
|
@@ -867,42 +849,42 @@ describe 'Blacklight::SolrHelper' do
|
|
867
849
|
end
|
868
850
|
|
869
851
|
it "should raise Blacklight::InvalidSolrID for an unknown id" do
|
870
|
-
|
852
|
+
lambda {
|
871
853
|
get_solr_response_for_doc_id(@bad_id)
|
872
|
-
}.
|
854
|
+
}.should raise_error(Blacklight::Exceptions::InvalidSolrID)
|
873
855
|
end
|
874
856
|
|
875
857
|
it "should use a provided document request handler " do
|
876
|
-
|
877
|
-
|
878
|
-
|
858
|
+
blacklight_config.stub(:document_solr_request_handler => 'document')
|
859
|
+
Blacklight.solr.should_receive(:get).with('select', kind_of(Hash)).and_return({'response'=>{'docs'=>[]}})
|
860
|
+
lambda { get_solr_response_for_doc_id(@doc_id)}.should raise_error Blacklight::Exceptions::InvalidSolrID
|
879
861
|
end
|
880
862
|
|
881
863
|
it "should have a non-nil result for a known id" do
|
882
|
-
|
864
|
+
@document.should_not == nil
|
883
865
|
end
|
884
866
|
it "should have a single document in the response for a known id" do
|
885
|
-
|
867
|
+
@response2.docs.size.should == 1
|
886
868
|
end
|
887
869
|
it 'should have the expected value in the id field' do
|
888
|
-
|
870
|
+
@document.id.should == @doc_id
|
889
871
|
end
|
890
872
|
it 'should have non-nil values for required fields set in initializer' do
|
891
|
-
|
892
|
-
|
893
|
-
|
873
|
+
@document.get(blacklight_config[:show][:html_title]).should_not == nil
|
874
|
+
@document.get(blacklight_config[:show][:heading]).should_not == nil
|
875
|
+
@document.get(blacklight_config[:show][:display_type]).should_not == nil
|
894
876
|
end
|
895
877
|
end
|
896
878
|
|
897
879
|
describe "solr_doc_params" do
|
898
880
|
it "should default to using the 'document' requestHandler" do
|
899
881
|
doc_params = solr_doc_params('asdfg')
|
900
|
-
|
882
|
+
doc_params[:qt].should == 'document'
|
901
883
|
end
|
902
884
|
|
903
885
|
|
904
886
|
describe "blacklight config's default_document_solr_parameters" do
|
905
|
-
def blacklight_config
|
887
|
+
def blacklight_config
|
906
888
|
config = Blacklight::Configuration.new
|
907
889
|
config.default_document_solr_params = { :qt => 'my_custom_handler', :asdf => '1234' }
|
908
890
|
config
|
@@ -910,15 +892,15 @@ describe 'Blacklight::SolrHelper' do
|
|
910
892
|
|
911
893
|
it "should use parameters from the controller's default_document_solr_parameters" do
|
912
894
|
doc_params = solr_doc_params('asdfg')
|
913
|
-
|
914
|
-
|
895
|
+
doc_params[:qt].should == 'my_custom_handler'
|
896
|
+
doc_params[:asdf].should == '1234'
|
915
897
|
end
|
916
898
|
end
|
917
899
|
|
918
900
|
end
|
919
901
|
|
920
902
|
describe "Get Document by custom unique id" do
|
921
|
-
=begin
|
903
|
+
=begin
|
922
904
|
# Can't test this properly without updating the "document" request handler in solr
|
923
905
|
it "should respect the configuration-supplied unique id" do
|
924
906
|
SolrDocument.should_receive(:unique_key).and_return("title_display")
|
@@ -929,7 +911,7 @@ describe 'Blacklight::SolrHelper' do
|
|
929
911
|
=end
|
930
912
|
it "should respect the configuration-supplied unique id" do
|
931
913
|
doc_params = solr_doc_params('"Strong Medicine speaks"')
|
932
|
-
|
914
|
+
doc_params[:id].should == '"Strong Medicine speaks"'
|
933
915
|
end
|
934
916
|
end
|
935
917
|
|
@@ -958,18 +940,18 @@ describe 'Blacklight::SolrHelper' do
|
|
958
940
|
=end
|
959
941
|
|
960
942
|
it 'should have a doc id field' do
|
961
|
-
|
943
|
+
@doc[:id].should_not == nil
|
962
944
|
end
|
963
945
|
|
964
946
|
it 'should have non-nil values for required fields set in initializer' do
|
965
|
-
|
966
|
-
|
967
|
-
|
947
|
+
@doc[blacklight_config.show.html_title].should_not == nil
|
948
|
+
@doc[blacklight_config.show.heading].should_not == nil
|
949
|
+
@doc[blacklight_config.show.display_type].should_not == nil
|
968
950
|
end
|
969
951
|
|
970
952
|
it "should limit search result by facets when supplied" do
|
971
953
|
doc2 = get_single_doc_via_search(@doc_row , :q => @all_docs_query, :f => @multi_facets)
|
972
|
-
|
954
|
+
doc2[:id].should_not == nil
|
973
955
|
end
|
974
956
|
|
975
957
|
end
|
@@ -978,15 +960,15 @@ describe 'Blacklight::SolrHelper' do
|
|
978
960
|
describe "Searches should return spelling suggestions", :integration => true do
|
979
961
|
it 'search results for just-poor-enough-query term should have (multiple) spelling suggestions' do
|
980
962
|
(solr_response, document_list) = get_search_results({:q => 'boo'})
|
981
|
-
|
982
|
-
|
963
|
+
solr_response.spelling.words.should include('bon')
|
964
|
+
solr_response.spelling.words.should include('bod') #for multiple suggestions
|
983
965
|
end
|
984
966
|
|
985
967
|
it 'search results for just-poor-enough-query term should have multiple spelling suggestions' do
|
986
968
|
(solr_response, document_list) = get_search_results({:q => 'politica'})
|
987
|
-
|
988
|
-
|
989
|
-
|
969
|
+
solr_response.spelling.words.should include('policy') # less freq
|
970
|
+
solr_response.spelling.words.should include('politics') # more freq
|
971
|
+
solr_response.spelling.words.should include('political') # more freq
|
990
972
|
=begin
|
991
973
|
# when we can have multiple suggestions
|
992
974
|
solr_response.spelling.words.should_not include('policy') # less freq
|
@@ -997,33 +979,39 @@ describe 'Blacklight::SolrHelper' do
|
|
997
979
|
|
998
980
|
it "title search results for just-poor-enough query term should have spelling suggestions" do
|
999
981
|
(solr_response, document_list) = get_search_results({:q => 'yehudiyam', :qt => 'search', :"spellcheck.dictionary" => "title"})
|
1000
|
-
|
982
|
+
solr_response.spelling.words.should include('yehudiyim')
|
1001
983
|
end
|
1002
984
|
|
1003
985
|
it "author search results for just-poor-enough-query term should have spelling suggestions" do
|
1004
986
|
(solr_response, document_list) = get_search_results({:q => 'shirma', :qt => 'search', :"spellcheck.dictionary" => "author"})
|
1005
|
-
|
987
|
+
solr_response.spelling.words.should include('sharma')
|
1006
988
|
end
|
1007
989
|
|
1008
990
|
it "subject search results for just-poor-enough-query term should have spelling suggestions" do
|
1009
991
|
(solr_response, document_list) = get_search_results({:q => 'wome', :qt => 'search', :"spellcheck.dictionary" => "subject"})
|
1010
|
-
|
992
|
+
solr_response.spelling.words.should include('women')
|
993
|
+
end
|
994
|
+
|
995
|
+
it 'search results for multiple terms query with just-poor-enough-terms should have spelling suggestions for each term' do
|
996
|
+
pending
|
997
|
+
# get_spelling_suggestion("histo politica").should_not be_nil
|
1011
998
|
end
|
999
|
+
|
1012
1000
|
end
|
1013
1001
|
|
1014
1002
|
describe "facet_limit_for" do
|
1015
1003
|
|
1016
1004
|
it "should return specified value for facet_field specified" do
|
1017
|
-
|
1005
|
+
facet_limit_for("subject_topic_facet").should == blacklight_config.facet_fields["subject_topic_facet"].limit
|
1018
1006
|
end
|
1019
1007
|
it "should generate proper solr param" do
|
1020
|
-
|
1008
|
+
solr_search_params[:"f.subject_topic_facet.facet.limit"].should == 21
|
1021
1009
|
end
|
1022
|
-
|
1010
|
+
|
1023
1011
|
it "facet_limit_hash should return hash with key being facet_field and value being configured limit" do
|
1024
1012
|
# facet_limit_hash has been removed from solrhelper in refactor. should it go back?
|
1025
1013
|
pending "facet_limit_hash has been removed from solrhelper in refactor. should it go back?"
|
1026
|
-
|
1014
|
+
facet_limit_hash.should == blacklight_config[:facet][:limits]
|
1027
1015
|
end
|
1028
1016
|
it "should handle no facet_limits in config" do
|
1029
1017
|
def blacklight_config
|
@@ -1031,61 +1019,61 @@ describe 'Blacklight::SolrHelper' do
|
|
1031
1019
|
config.facet_fields = {}
|
1032
1020
|
return config
|
1033
1021
|
end
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1022
|
+
|
1023
|
+
facet_limit_for("subject_topic_facet").should be_nil
|
1024
|
+
|
1025
|
+
solr_search_params.should_not have_key(:"f.subject_topic_facet.facet.limit")
|
1026
|
+
|
1039
1027
|
end
|
1040
|
-
|
1028
|
+
|
1041
1029
|
describe "for 'true' configured values" do
|
1042
1030
|
it "should return nil if no @response available" do
|
1043
|
-
|
1031
|
+
facet_limit_for("some_unknown_field").should be_nil
|
1044
1032
|
end
|
1045
|
-
it "should get from @response facet.limit if available" do
|
1033
|
+
it "should get from @response facet.limit if available" do
|
1046
1034
|
# Okay, this is cheesy, since we included SolrHelper directly
|
1047
1035
|
# into our example groups, we need to set an iVar here, so it will
|
1048
|
-
# use it.
|
1049
|
-
@response = {"responseHeader" => {"params" => {"facet.limit" => 11}}}
|
1050
|
-
|
1036
|
+
# use it.
|
1037
|
+
@response = {"responseHeader" => {"params" => {"facet.limit" => 11}}}
|
1038
|
+
facet_limit_for("language_facet").should == 10
|
1051
1039
|
end
|
1052
1040
|
it "should get from specific field in @response if available" do
|
1053
1041
|
@response = {"responseHeader" => {"params" => {"facet.limit" => 11,"f.language_facet.facet.limit" => 16}}}
|
1054
|
-
|
1042
|
+
facet_limit_for("language_facet").should == 15
|
1055
1043
|
end
|
1056
1044
|
end
|
1057
1045
|
end
|
1058
1046
|
|
1059
1047
|
describe "with max per page enforced" do
|
1060
|
-
def blacklight_config
|
1048
|
+
def blacklight_config
|
1061
1049
|
config = Blacklight::Configuration.new
|
1062
1050
|
config.max_per_page = 123
|
1063
1051
|
return config
|
1064
1052
|
end
|
1065
1053
|
|
1066
1054
|
it "should enforce max_per_page against all parameters" do
|
1067
|
-
|
1068
|
-
|
1069
|
-
end
|
1055
|
+
blacklight_config.max_per_page.should == 123
|
1056
|
+
solr_search_params(:per_page => 98765)[:rows].should == 123
|
1057
|
+
end
|
1070
1058
|
end
|
1071
1059
|
|
1072
1060
|
describe "#get_solr_response_for_field_values" do
|
1073
1061
|
before do
|
1074
1062
|
@mock_response = double()
|
1075
|
-
|
1063
|
+
@mock_response.stub(:docs => [])
|
1076
1064
|
end
|
1077
1065
|
it "should contruct a solr query based on the field and value pair" do
|
1078
|
-
|
1066
|
+
self.should_receive(:find).with(an_instance_of(String), hash_including(:q => "field_name:(value)")).and_return(@mock_response)
|
1079
1067
|
get_solr_response_for_field_values('field_name', 'value')
|
1080
1068
|
end
|
1081
1069
|
|
1082
1070
|
it "should OR multiple values together" do
|
1083
|
-
|
1071
|
+
self.should_receive(:find).with(an_instance_of(String), hash_including(:q => "field_name:(a OR b)")).and_return(@mock_response)
|
1084
1072
|
get_solr_response_for_field_values('field_name', ['a', 'b'])
|
1085
1073
|
end
|
1086
1074
|
|
1087
1075
|
it "should escape crazy identifiers" do
|
1088
|
-
|
1076
|
+
self.should_receive(:find).with(an_instance_of(String), hash_including(:q => "field_name:(\"h://\\\"\\\'\")")).and_return(@mock_response)
|
1089
1077
|
get_solr_response_for_field_values('field_name', 'h://"\'')
|
1090
1078
|
end
|
1091
1079
|
end
|
@@ -1098,7 +1086,7 @@ describe 'Blacklight::SolrHelper' do
|
|
1098
1086
|
# more like this
|
1099
1087
|
# nearby on shelf
|
1100
1088
|
it "should raise a Blacklight exception if RSolr can't connect to the Solr instance" do
|
1101
|
-
|
1089
|
+
Blacklight.solr.stub(:get).and_raise(Errno::ECONNREFUSED)
|
1102
1090
|
expect { find(:a => 123) }.to raise_exception(/Unable to connect to Solr instance/)
|
1103
1091
|
end
|
1104
1092
|
|
@@ -1110,7 +1098,7 @@ describe 'Blacklight::SolrHelper' do
|
|
1110
1098
|
it "should pull the grouped key out of the config" do
|
1111
1099
|
blacklight_config.index.group = 'xyz'
|
1112
1100
|
expect(self.grouped_key_for_results).to eq('xyz')
|
1113
|
-
end
|
1101
|
+
end
|
1114
1102
|
end
|
1115
1103
|
|
1116
1104
|
describe "#with_tag_ex" do
|
@@ -1158,39 +1146,5 @@ describe 'Blacklight::SolrHelper' do
|
|
1158
1146
|
end
|
1159
1147
|
end
|
1160
1148
|
|
1161
|
-
describe "http_method configuration" do
|
1162
|
-
describe "using default" do
|
1163
|
-
let (:blacklight_config) {Blacklight::Configuration.new}
|
1164
|
-
|
1165
|
-
it "defaults to get" do
|
1166
|
-
expect(blacklight_config.http_method).to eq :get
|
1167
|
-
expect(blacklight_solr).to receive(:send_and_receive) { |path, params|
|
1168
|
-
expect(path).to eq 'select'
|
1169
|
-
expect(params[:method]).to eq :get
|
1170
|
-
expect(params[:params]).to include(:q)
|
1171
|
-
}.and_return({'response'=>{'docs'=>[]}})
|
1172
|
-
get_search_results(:q => @all_docs_query)
|
1173
|
-
end
|
1174
|
-
end
|
1175
|
-
|
1176
|
-
describe "setting to post" do
|
1177
|
-
let (:blacklight_config) {config = Blacklight::Configuration.new; config.http_method=:post; config}
|
1178
|
-
|
1179
|
-
it "keep value set to post" do
|
1180
|
-
expect(blacklight_config.http_method).to eq :post
|
1181
|
-
expect(blacklight_solr).to receive(:send_and_receive) { |path, params|
|
1182
|
-
expect(path).to eq 'select'
|
1183
|
-
expect(params[:method]).to eq :post
|
1184
|
-
expect(params[:data]).to include(:q)
|
1185
|
-
}.and_return({'response'=>{'docs'=>[]}})
|
1186
|
-
get_search_results(:q => @all_docs_query)
|
1187
|
-
end
|
1188
|
-
|
1189
|
-
it "should send a post request to solr", :integration => true do
|
1190
|
-
response, docs = get_search_results(:q => @all_docs_query)
|
1191
|
-
expect(docs.length).to be >= 1
|
1192
|
-
end
|
1193
|
-
end
|
1194
|
-
end
|
1195
|
-
|
1196
1149
|
end
|
1150
|
+
|