blacklight 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +0 -6
- data/Gemfile +5 -0
- data/README.md +1 -1
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight/autofocus.js +16 -0
- data/app/assets/javascripts/blacklight/blacklight.js +1 -0
- data/app/assets/javascripts/blacklight/bookmark_toggle.js +2 -5
- data/app/assets/javascripts/blacklight/checkbox_submit.js +3 -6
- data/app/assets/javascripts/blacklight/core.js +24 -1
- data/app/assets/javascripts/blacklight/css_dropdowns.js +2 -2
- data/app/assets/javascripts/blacklight/facet_expand_contract.js +4 -3
- data/app/assets/javascripts/blacklight/lightbox_dialog.js +7 -1
- data/app/assets/javascripts/blacklight/search_context.js +1 -1
- data/app/assets/javascripts/blacklight/select_submit.js +1 -1
- data/app/assets/javascripts/blacklight/zebra_stripe.js +1 -1
- data/app/assets/stylesheets/blacklight/_blacklight_base.css.scss +1 -0
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +5 -0
- data/app/assets/stylesheets/blacklight/_facets.css.scss +6 -0
- data/app/assets/stylesheets/blacklight/_group.css.scss +14 -0
- data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +1 -0
- data/app/controllers/bookmarks_controller.rb +2 -2
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +41 -24
- data/app/helpers/blacklight/catalog_helper_behavior.rb +48 -28
- data/app/helpers/blacklight/facets_helper_behavior.rb +9 -75
- data/app/models/record_mailer.rb +1 -16
- data/app/views/bookmarks/index.html.erb +2 -0
- data/app/views/catalog/_bookmark_control.html.erb +3 -4
- data/app/views/catalog/_document.html.erb +2 -1
- data/app/views/catalog/_document_header.html.erb +6 -3
- data/app/views/catalog/_email_form.html.erb +0 -7
- data/app/views/catalog/_facet_layout.html.erb +1 -1
- data/app/views/catalog/_group_default.html.erb +12 -0
- data/app/views/catalog/_index_default.html.erb +1 -1
- data/app/views/catalog/_opensearch_response_metadata.html.erb +2 -3
- data/app/views/catalog/_paginate_compact.html.erb +2 -2
- data/app/views/catalog/_results_pagination.html.erb +2 -2
- data/app/views/catalog/_search_form.html.erb +1 -1
- data/app/views/catalog/_sms_form.html.erb +1 -21
- data/app/views/catalog/_thumbnail_default.html.erb +5 -0
- data/app/views/catalog/email_sent.html.erb +9 -0
- data/app/views/catalog/index.atom.builder +7 -8
- data/app/views/catalog/index.html.erb +6 -3
- data/app/views/catalog/librarian_view.html.erb +1 -1
- data/app/views/catalog/sms_sent.html.erb +9 -0
- data/app/views/feedback/complete.html.erb +2 -0
- data/app/views/feedback/show.html.erb +7 -5
- data/app/views/kaminari/blacklight_compact/_paginator.html.erb +1 -1
- data/app/views/layouts/blacklight.html.erb +1 -2
- data/app/views/saved_searches/index.html.erb +2 -0
- data/app/views/search_history/index.html.erb +1 -1
- data/blacklight.gemspec +1 -1
- data/config/locales/blacklight.en.yml +11 -0
- data/config/locales/blacklight.fr.yml +15 -1
- data/gemfiles/rails3.gemfile +7 -0
- data/gemfiles/rails4.gemfile +7 -0
- data/lib/blacklight.rb +1 -0
- data/lib/blacklight/catalog.rb +101 -56
- data/lib/blacklight/configuration.rb +1 -1
- data/lib/blacklight/controller.rb +7 -4
- data/lib/blacklight/facet.rb +79 -0
- data/lib/blacklight/routes.rb +0 -1
- data/lib/blacklight/solr/document.rb +4 -0
- data/lib/blacklight/solr/document/marc_export.rb +1 -1
- data/lib/blacklight/solr_helper.rb +39 -8
- data/lib/blacklight/solr_response.rb +35 -3
- data/lib/blacklight/solr_response/facets.rb +4 -0
- data/lib/blacklight/solr_response/group.rb +33 -0
- data/lib/blacklight/solr_response/group_response.rb +49 -0
- data/lib/blacklight/solr_response/pagination_methods.rb +27 -0
- data/lib/blacklight/user.rb +30 -32
- data/lib/generators/blacklight/assets_generator.rb +3 -1
- data/lib/generators/blacklight/blacklight_generator.rb +28 -125
- data/lib/generators/blacklight/marc_generator.rb +66 -0
- data/lib/generators/blacklight/models_generator.rb +113 -0
- data/lib/generators/blacklight/templates/alternate_controller.rb +9 -0
- data/lib/generators/blacklight/templates/config/solr.yml +0 -2
- data/lib/generators/blacklight/templates/solr_document.rb +1 -13
- data/lib/railties/all_tests.rake +5 -8
- data/spec/controllers/catalog_controller_spec.rb +185 -113
- data/spec/features/alternate_controller_spec.rb +34 -0
- data/spec/features/bookmarks_spec.rb +58 -0
- data/spec/features/did_you_mean_spec.rb +135 -0
- data/spec/features/librarian_view_spec.rb +13 -0
- data/spec/features/record_view_spec.rb +37 -0
- data/spec/features/saved_searches_spec.rb +47 -0
- data/spec/features/search_filters_spec.rb +137 -0
- data/spec/features/search_history_spec.rb +75 -0
- data/spec/features/search_pagination_spec.rb +91 -0
- data/spec/features/search_results_spec.rb +68 -0
- data/spec/features/search_sort_spec.rb +20 -0
- data/spec/features/search_spec.rb +108 -0
- data/spec/helpers/blacklight_helper_spec.rb +45 -2
- data/spec/helpers/catalog_helper_spec.rb +134 -1
- data/spec/helpers/facets_helper_spec.rb +8 -0
- data/spec/lib/blacklight/solr_response/group_response_spec.rb +78 -0
- data/spec/lib/blacklight/solr_response/group_spec.rb +70 -0
- data/spec/lib/blacklight_solr_response_spec.rb +11 -5
- data/spec/lib/blacklight_user_spec.rb +22 -41
- data/spec/lib/solr_helper_spec.rb +73 -1
- data/spec/models/record_mailer_spec.rb +3 -3
- data/spec/models/{solr_docment_spec.rb → solr_document_spec.rb} +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/support/features.rb +7 -0
- data/spec/support/features/session_helpers.rb +22 -0
- data/spec/test_app_templates/Gemfile.extra +0 -4
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -6
- data/spec/test_app_templates/lib/tasks/blacklight_test_app.rake +1 -9
- data/spec/views/catalog/_facets.html.erb_spec.rb +2 -1
- data/tasks/blacklight.rake +0 -10
- metadata +49 -58
- data/features/bookmarks.feature +0 -68
- data/features/did_you_mean.feature +0 -123
- data/features/librarian_view.feature +0 -18
- data/features/record_view.feature +0 -40
- data/features/saved_searches.feature +0 -49
- data/features/search.feature +0 -83
- data/features/search_filters.feature +0 -119
- data/features/search_history.feature +0 -85
- data/features/search_pagination.feature +0 -53
- data/features/search_results.feature +0 -61
- data/features/search_sort.feature +0 -27
- data/features/step_definitions/bookmarks_steps.rb +0 -6
- data/features/step_definitions/error_steps.rb +0 -5
- data/features/step_definitions/general_steps.rb +0 -50
- data/features/step_definitions/record_view_steps.rb +0 -12
- data/features/step_definitions/saved_searches_steps.rb +0 -19
- data/features/step_definitions/search_facets_steps.rb +0 -29
- data/features/step_definitions/search_history_steps.rb +0 -9
- data/features/step_definitions/search_pagination_steps.rb +0 -29
- data/features/step_definitions/search_result_steps.rb +0 -115
- data/features/step_definitions/search_steps.rb +0 -118
- data/features/step_definitions/user_steps.rb +0 -5
- data/features/step_definitions/web_steps.rb +0 -217
- data/features/support/env.rb +0 -65
- data/features/support/paths.rb +0 -48
- data/features/support/selectors.rb +0 -40
- data/lib/railties/blacklight_cucumber.rake +0 -126
- data/lib/solrmarc.log.1 +0 -854
|
@@ -18,7 +18,7 @@ module Blacklight
|
|
|
18
18
|
:document_solr_request_handler => nil,
|
|
19
19
|
:default_document_solr_params => {},
|
|
20
20
|
:show => OpenStructWithHashAccess.new(:html_title => unique_key, :heading => unique_key),
|
|
21
|
-
:index => OpenStructWithHashAccess.new(:show_link => unique_key),
|
|
21
|
+
:index => OpenStructWithHashAccess.new(:show_link => unique_key, :record_display_type => 'format', :group => false),
|
|
22
22
|
:spell_max => 5,
|
|
23
23
|
:max_per_page => 100,
|
|
24
24
|
:per_page => [10,20,50,100],
|
|
@@ -99,14 +99,17 @@ module Blacklight::Controller
|
|
|
99
99
|
current_user_bookmarks = current_user.bookmarks.all.collect(&:document_id)
|
|
100
100
|
|
|
101
101
|
guest_user.searches.all.reject { |s| current_user_searches.include?(s.query_params)}.each do |s|
|
|
102
|
-
|
|
103
|
-
s.save
|
|
102
|
+
current_user.searches << s
|
|
103
|
+
s.save!
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
guest_user.bookmarks.all.reject { |b| current_user_bookmarks.include?(b.document_id)}.each do |b|
|
|
107
|
-
|
|
108
|
-
b.save
|
|
107
|
+
current_user.bookmarks << b
|
|
108
|
+
b.save!
|
|
109
109
|
end
|
|
110
|
+
|
|
111
|
+
# let guest_user know we've moved some bookmarks from under it
|
|
112
|
+
guest_user.reload if guest_user.persisted?
|
|
110
113
|
end
|
|
111
114
|
|
|
112
115
|
##
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# These are methods that are used at both the view helper and controller layers
|
|
2
|
+
# They are only dependent on `blacklight_config` and `@response`
|
|
3
|
+
#
|
|
4
|
+
module Blacklight
|
|
5
|
+
module Facet
|
|
6
|
+
def facets_from_request(fields = facet_field_names)
|
|
7
|
+
fields.map { |solr_field| facet_by_field_name(solr_field) }.compact
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def facet_field_names
|
|
11
|
+
blacklight_config.facet_fields.keys
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def facet_configuration_for_field(field)
|
|
15
|
+
blacklight_config.facet_fields[field] || Blacklight::Configuration::FacetField.new(:field => field).normalize!
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Get a FacetField object from the @response
|
|
20
|
+
def facet_by_field_name solr_field
|
|
21
|
+
case solr_field
|
|
22
|
+
when String, Symbol
|
|
23
|
+
extract_solr_facet_by_field_name(solr_field)
|
|
24
|
+
when Blacklight::Configuration::FacetField
|
|
25
|
+
extract_solr_facet_by_field_name(solr_field.field)
|
|
26
|
+
else
|
|
27
|
+
solr_field
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
# Get the solr response for the solr field :field
|
|
34
|
+
def extract_solr_facet_by_field_name facet_name
|
|
35
|
+
facet_field = facet_configuration_for_field(facet_name)
|
|
36
|
+
case
|
|
37
|
+
when (facet_field.respond_to?(:query) and facet_field.query)
|
|
38
|
+
create_rsolr_facet_field_response_for_query_facet_field facet_name, facet_field
|
|
39
|
+
when (facet_field.respond_to?(:pivot) and facet_field.pivot)
|
|
40
|
+
create_rsolr_facet_field_response_for_pivot_facet_field facet_name, facet_field
|
|
41
|
+
else
|
|
42
|
+
@response.facet_by_field_name(facet_name)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def create_rsolr_facet_field_response_for_query_facet_field facet_name, facet_field
|
|
47
|
+
salient_facet_queries = facet_field.query.map { |k, x| x[:fq] }
|
|
48
|
+
items = []
|
|
49
|
+
@response.facet_queries.select { |k,v| salient_facet_queries.include?(k) }.reject { |value, hits| hits == 0 }.map do |value,hits|
|
|
50
|
+
salient_fields = facet_field.query.select { |key, val| val[:fq] == value }
|
|
51
|
+
key = ((salient_fields.keys if salient_fields.respond_to? :keys) || salient_fields.first).first
|
|
52
|
+
items << Blacklight::SolrResponse::Facets::FacetItem.new(:value => key, :hits => hits, :label => facet_field.query[key][:label])
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
Blacklight::SolrResponse::Facets::FacetField.new facet_name, items
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def create_rsolr_facet_field_response_for_pivot_facet_field facet_name, facet_field
|
|
60
|
+
items = []
|
|
61
|
+
(@response.facet_pivot[facet_field.pivot.join(",")] || []).map do |lst|
|
|
62
|
+
items << construct_pivot_field(lst)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
Blacklight::SolrResponse::Facets::FacetField.new facet_name, items
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def construct_pivot_field lst, parent_fq = {}
|
|
69
|
+
items = []
|
|
70
|
+
|
|
71
|
+
lst[:pivot].each do |i|
|
|
72
|
+
items << construct_pivot_field(i, parent_fq.merge({ lst[:field] => lst[:value] }))
|
|
73
|
+
end if lst[:pivot]
|
|
74
|
+
|
|
75
|
+
Blacklight::SolrResponse::Facets::FacetItem.new(:value => lst[:value], :hits => lst[:count], :field => lst[:field], :items => items, :fq => parent_fq)
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/lib/blacklight/routes.rb
CHANGED
|
@@ -62,7 +62,6 @@ module Blacklight
|
|
|
62
62
|
post 'catalog/email'
|
|
63
63
|
get 'catalog/sms', :as => "sms_catalog"
|
|
64
64
|
get 'catalog/endnote', :as => "endnote_catalog"
|
|
65
|
-
get 'catalog/send_email_record', :as => "send_email_record_catalog"
|
|
66
65
|
get "catalog/facet/:id", :to => 'catalog#facet', :as => 'catalog_facet'
|
|
67
66
|
|
|
68
67
|
|
|
@@ -94,7 +94,7 @@ module Blacklight::Solr::Document::MarcExport
|
|
|
94
94
|
export_text << "&rft.pub=" + ((publisher_info.nil? or publisher_info['b'].nil?) ? "" : CGI::escape(publisher_info['b']))
|
|
95
95
|
export_text << "&rft.format=" + (format.nil? ? "" : CGI::escape(format))
|
|
96
96
|
end
|
|
97
|
-
export_text unless export_text.blank?
|
|
97
|
+
export_text.html_safe unless export_text.blank?
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
module Blacklight::SolrHelper
|
|
48
48
|
extend ActiveSupport::Concern
|
|
49
49
|
include Blacklight::SearchFields
|
|
50
|
+
include Blacklight::Facet
|
|
50
51
|
|
|
51
52
|
included do
|
|
52
53
|
if self.respond_to?(:helper_method)
|
|
@@ -66,7 +67,7 @@ module Blacklight::SolrHelper
|
|
|
66
67
|
# CatalogController.include ModuleDefiningNewMethod
|
|
67
68
|
# CatalogController.solr_search_params_logic += [:new_method]
|
|
68
69
|
# CatalogController.solr_search_params_logic.delete(:we_dont_want)
|
|
69
|
-
self.solr_search_params_logic = [:default_solr_parameters , :add_query_to_solr, :add_facet_fq_to_solr, :add_facetting_to_solr, :add_solr_fields_to_query, :add_paging_to_solr, :add_sorting_to_solr ]
|
|
70
|
+
self.solr_search_params_logic = [:default_solr_parameters , :add_query_to_solr, :add_facet_fq_to_solr, :add_facetting_to_solr, :add_solr_fields_to_query, :add_paging_to_solr, :add_sorting_to_solr, :add_group_config_to_solr ]
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
def force_to_utf8(value)
|
|
@@ -95,7 +96,7 @@ module Blacklight::SolrHelper
|
|
|
95
96
|
# if needed.
|
|
96
97
|
def solr_param_quote(val, options = {})
|
|
97
98
|
options[:quote] ||= '"'
|
|
98
|
-
unless val =~ /^[a-zA-
|
|
99
|
+
unless val =~ /^[a-zA-Z0-9$_\-\^]+$/
|
|
99
100
|
val = options[:quote] +
|
|
100
101
|
# Yes, we need crazy escaping here, to deal with regexp esc too!
|
|
101
102
|
val.gsub("'", "\\\\\'").gsub('"', "\\\\\"") +
|
|
@@ -327,13 +328,14 @@ module Blacklight::SolrHelper
|
|
|
327
328
|
if blacklight_config.add_facet_fields_to_solr_request
|
|
328
329
|
case
|
|
329
330
|
when facet.pivot
|
|
330
|
-
solr_parameters[:'facet.pivot'] << facet.pivot.join(",")
|
|
331
|
+
solr_parameters[:'facet.pivot'] << with_ex_local_param(facet.ex, facet.pivot.join(","))
|
|
331
332
|
when facet.query
|
|
332
|
-
solr_parameters[:'facet.query'] += facet.query.map { |k, x| x[:fq] }
|
|
333
|
+
solr_parameters[:'facet.query'] += facet.query.map { |k, x| with_ex_local_param(facet.ex, x[:fq]) }
|
|
333
334
|
|
|
334
335
|
when facet.ex
|
|
335
|
-
idx = solr_parameters[:'facet.field'].index(facet.field)
|
|
336
|
-
|
|
336
|
+
if idx = solr_parameters[:'facet.field'].index(facet.field)
|
|
337
|
+
solr_parameters[:'facet.field'][idx] = with_ex_local_param(facet.ex, solr_parameters[:'facet.field'][idx])
|
|
338
|
+
end
|
|
337
339
|
end
|
|
338
340
|
|
|
339
341
|
if facet.sort
|
|
@@ -348,6 +350,14 @@ module Blacklight::SolrHelper
|
|
|
348
350
|
end
|
|
349
351
|
end
|
|
350
352
|
|
|
353
|
+
def with_ex_local_param(ex, value)
|
|
354
|
+
if ex
|
|
355
|
+
"{!ex=#{ex}}#{value}"
|
|
356
|
+
else
|
|
357
|
+
value
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
351
361
|
def add_solr_fields_to_query solr_parameters, user_parameters
|
|
352
362
|
return unless blacklight_config.add_field_configuration_to_solr_request
|
|
353
363
|
blacklight_config.index_fields.each do |field_name, field|
|
|
@@ -359,6 +369,13 @@ module Blacklight::SolrHelper
|
|
|
359
369
|
end
|
|
360
370
|
end
|
|
361
371
|
|
|
372
|
+
# Remove the group parameter if we've faceted on the group field (e.g. for the full results for a group)
|
|
373
|
+
def add_group_config_to_solr solr_parameters, user_parameters
|
|
374
|
+
if user_parameters[:f] and user_parameters[:f][grouped_key_for_results]
|
|
375
|
+
solr_parameters[:group] = false
|
|
376
|
+
end
|
|
377
|
+
end
|
|
378
|
+
|
|
362
379
|
|
|
363
380
|
|
|
364
381
|
# a solr query method
|
|
@@ -369,8 +386,16 @@ module Blacklight::SolrHelper
|
|
|
369
386
|
# and second an array of SolrDocuments representing the response.docs
|
|
370
387
|
def get_search_results(user_params = params || {}, extra_controller_params = {})
|
|
371
388
|
solr_response = query_solr(user_params, extra_controller_params)
|
|
372
|
-
|
|
373
|
-
|
|
389
|
+
|
|
390
|
+
case
|
|
391
|
+
when (solr_response.grouped? && grouped_key_for_results)
|
|
392
|
+
[solr_response.group(grouped_key_for_results), []]
|
|
393
|
+
when (solr_response.grouped? && solr_response.grouped.length == 1)
|
|
394
|
+
[solr_response.grouped.first, []]
|
|
395
|
+
else
|
|
396
|
+
document_list = solr_response.docs.collect {|doc| SolrDocument.new(doc, solr_response)}
|
|
397
|
+
[solr_response, document_list]
|
|
398
|
+
end
|
|
374
399
|
end
|
|
375
400
|
|
|
376
401
|
|
|
@@ -580,4 +605,10 @@ module Blacklight::SolrHelper
|
|
|
580
605
|
return limit
|
|
581
606
|
end
|
|
582
607
|
|
|
608
|
+
##
|
|
609
|
+
# The key to use to retrieve the grouped field to display
|
|
610
|
+
def grouped_key_for_results
|
|
611
|
+
blacklight_config.index.group
|
|
612
|
+
end
|
|
613
|
+
|
|
583
614
|
end
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
require 'kaminari'
|
|
2
|
+
|
|
1
3
|
class Blacklight::SolrResponse < HashWithIndifferentAccess
|
|
2
4
|
|
|
5
|
+
require 'blacklight/solr_response/pagination_methods'
|
|
6
|
+
|
|
3
7
|
autoload :Spelling, 'blacklight/solr_response/spelling'
|
|
4
8
|
autoload :Facets, 'blacklight/solr_response/facets'
|
|
5
9
|
autoload :MoreLikeThis, 'blacklight/solr_response/more_like_this'
|
|
10
|
+
autoload :GroupResponse, 'blacklight/solr_response/group_response'
|
|
11
|
+
autoload :Group, 'blacklight/solr_response/group'
|
|
12
|
+
|
|
13
|
+
include PaginationMethods
|
|
6
14
|
|
|
7
15
|
attr_reader :request_params
|
|
8
16
|
def initialize(data, request_params)
|
|
@@ -18,7 +26,6 @@ class Blacklight::SolrResponse < HashWithIndifferentAccess
|
|
|
18
26
|
self['responseHeader']
|
|
19
27
|
end
|
|
20
28
|
|
|
21
|
-
|
|
22
29
|
def update(other_hash)
|
|
23
30
|
other_hash.each_pair { |key, value| self[key] = value }
|
|
24
31
|
self
|
|
@@ -34,7 +41,7 @@ class Blacklight::SolrResponse < HashWithIndifferentAccess
|
|
|
34
41
|
|
|
35
42
|
def docs
|
|
36
43
|
@docs ||= begin
|
|
37
|
-
response['docs']
|
|
44
|
+
response['docs'] || []
|
|
38
45
|
end
|
|
39
46
|
end
|
|
40
47
|
|
|
@@ -42,9 +49,34 @@ class Blacklight::SolrResponse < HashWithIndifferentAccess
|
|
|
42
49
|
self['spelling']
|
|
43
50
|
end
|
|
44
51
|
|
|
52
|
+
def grouped
|
|
53
|
+
@groups ||= self["grouped"].map do |field, group|
|
|
54
|
+
# grouped responses can either be grouped by:
|
|
55
|
+
# - field, where this key is the field name, and there will be a list
|
|
56
|
+
# of documents grouped by field value, or:
|
|
57
|
+
# - function, where the key is the function, and the documents will be
|
|
58
|
+
# further grouped by function value, or:
|
|
59
|
+
# - query, where the key is the query, and the matching documents will be
|
|
60
|
+
# in the doclist on THIS object
|
|
61
|
+
if group["groups"] # field or function
|
|
62
|
+
GroupResponse.new field, group, self
|
|
63
|
+
else # query
|
|
64
|
+
Group.new field, group, self
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def group key
|
|
70
|
+
grouped.select { |x| x.key == key }.first
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def grouped?
|
|
74
|
+
self.has_key? "grouped"
|
|
75
|
+
end
|
|
76
|
+
|
|
45
77
|
module Response
|
|
46
78
|
def response
|
|
47
|
-
self[:response]
|
|
79
|
+
self[:response] || {}
|
|
48
80
|
end
|
|
49
81
|
|
|
50
82
|
# short cut to response['numFound']
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class Blacklight::SolrResponse::Group
|
|
2
|
+
|
|
3
|
+
include Blacklight::SolrResponse::PaginationMethods
|
|
4
|
+
|
|
5
|
+
attr_reader :key, :group, :response
|
|
6
|
+
|
|
7
|
+
def initialize key, group, response
|
|
8
|
+
@key = key
|
|
9
|
+
@group = group
|
|
10
|
+
@response = response
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def doclist
|
|
14
|
+
group[:doclist]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# short cut to response['numFound']
|
|
18
|
+
def total
|
|
19
|
+
doclist[:numFound].to_s.to_i
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def start
|
|
23
|
+
doclist[:start].to_s.to_i
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def docs
|
|
27
|
+
doclist[:docs].map {|doc| SolrDocument.new(doc, response)}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def field
|
|
31
|
+
response.group_field
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
class Blacklight::SolrResponse::GroupResponse
|
|
2
|
+
|
|
3
|
+
include Blacklight::SolrResponse::PaginationMethods
|
|
4
|
+
|
|
5
|
+
attr_reader :key, :group, :response
|
|
6
|
+
|
|
7
|
+
def initialize key, group, response
|
|
8
|
+
@key = key
|
|
9
|
+
@group = group
|
|
10
|
+
@response = response
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
alias_method :group_field, :key
|
|
14
|
+
|
|
15
|
+
def groups
|
|
16
|
+
@groups ||= group["groups"].map do |g|
|
|
17
|
+
Blacklight::SolrResponse::Group.new g[:groupValue], g, self
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def group_limit
|
|
22
|
+
params.fetch(:'group.limit', 1).to_s.to_i
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def total
|
|
26
|
+
# ngroups is only available in Solr 4.1+
|
|
27
|
+
# fall back on the number of facet items for that field?
|
|
28
|
+
(group["ngroups"] || (response.facet_by_field_name(key) || []).length).to_s.to_i
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def start
|
|
32
|
+
params[:start].to_s.to_i
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def method_missing meth, *args, &block
|
|
36
|
+
|
|
37
|
+
if response.respond_to? meth
|
|
38
|
+
response.send(meth, *args, &block)
|
|
39
|
+
else
|
|
40
|
+
super
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def respond_to? meth
|
|
46
|
+
response.respond_to?(meth) || super
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Blacklight::SolrResponse::PaginationMethods
|
|
2
|
+
|
|
3
|
+
include Kaminari::PageScopeMethods
|
|
4
|
+
|
|
5
|
+
def limit_value #:nodoc:
|
|
6
|
+
rows
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def offset_value #:nodoc:
|
|
10
|
+
start
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def total_count #:nodoc:
|
|
14
|
+
total
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
## Methods in kaminari master that we'd like to use today.
|
|
18
|
+
# Next page number in the collection
|
|
19
|
+
def next_page
|
|
20
|
+
current_page + 1 unless last_page?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Previous page number in the collection
|
|
24
|
+
def prev_page
|
|
25
|
+
current_page - 1 unless first_page?
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/blacklight/user.rb
CHANGED
|
@@ -6,46 +6,44 @@ module Blacklight::User
|
|
|
6
6
|
# SEE ALSO: The /lib/blacklight/engine.rb class for how when this
|
|
7
7
|
# is injected into the hosting application through ActiveRecord::Base extend
|
|
8
8
|
def self.included(base)
|
|
9
|
-
base.
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if base.respond_to? :has_many
|
|
10
|
+
base.send :has_many, :bookmarks, :dependent => :destroy, :as => :user
|
|
11
|
+
base.send :has_many, :searches, :dependent => :destroy, :as => :user
|
|
12
|
+
end
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
#
|
|
15
|
-
#
|
|
15
|
+
# This is left for backwards-compatibility
|
|
16
|
+
# Remove this in Blacklight 5.x
|
|
16
17
|
module InstanceMethods
|
|
18
|
+
include Blacklight::User
|
|
19
|
+
end
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
def has_bookmarks?
|
|
22
|
+
bookmarks.any?
|
|
23
|
+
end
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
def has_searches?
|
|
26
|
+
searches.any?
|
|
27
|
+
end
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
def bookmarked_document_ids
|
|
30
|
+
self.bookmarks.pluck(:document_id)
|
|
31
|
+
end
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
# see #current_bookmark_for, is easier
|
|
34
|
+
def document_is_bookmarked?(document_id)
|
|
35
|
+
bookmarked_document_ids.include? document_id.to_s
|
|
36
|
+
end
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
self.bookmarks.to_a.find {|b| b.document_id == document_id}
|
|
41
|
-
end
|
|
38
|
+
# returns a Bookmark object if there is one for document_id, else
|
|
39
|
+
# nil.
|
|
40
|
+
def existing_bookmark_for(document_id)
|
|
41
|
+
self.bookmarks.where(:document_id => document_id).first
|
|
42
|
+
end
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
end
|
|
44
|
+
def documents_to_bookmark=(docs)
|
|
45
|
+
docs.reject { |doc| document_is_bookmarked?(doc[:document_id]) }.each do |doc|
|
|
46
|
+
self.bookmarks.create(doc)
|
|
47
47
|
end
|
|
48
|
-
|
|
49
|
-
end # /InstanceMethods
|
|
50
|
-
|
|
48
|
+
end
|
|
51
49
|
end
|