blacklight 4.3.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +0 -6
  4. data/Gemfile +5 -0
  5. data/README.md +1 -1
  6. data/Rakefile +0 -1
  7. data/VERSION +1 -1
  8. data/app/assets/javascripts/blacklight/autofocus.js +16 -0
  9. data/app/assets/javascripts/blacklight/blacklight.js +1 -0
  10. data/app/assets/javascripts/blacklight/bookmark_toggle.js +2 -5
  11. data/app/assets/javascripts/blacklight/checkbox_submit.js +3 -6
  12. data/app/assets/javascripts/blacklight/core.js +24 -1
  13. data/app/assets/javascripts/blacklight/css_dropdowns.js +2 -2
  14. data/app/assets/javascripts/blacklight/facet_expand_contract.js +4 -3
  15. data/app/assets/javascripts/blacklight/lightbox_dialog.js +7 -1
  16. data/app/assets/javascripts/blacklight/search_context.js +1 -1
  17. data/app/assets/javascripts/blacklight/select_submit.js +1 -1
  18. data/app/assets/javascripts/blacklight/zebra_stripe.js +1 -1
  19. data/app/assets/stylesheets/blacklight/_blacklight_base.css.scss +1 -0
  20. data/app/assets/stylesheets/blacklight/_catalog.css.scss +5 -0
  21. data/app/assets/stylesheets/blacklight/_facets.css.scss +6 -0
  22. data/app/assets/stylesheets/blacklight/_group.css.scss +14 -0
  23. data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +1 -0
  24. data/app/controllers/bookmarks_controller.rb +2 -2
  25. data/app/helpers/blacklight/blacklight_helper_behavior.rb +41 -24
  26. data/app/helpers/blacklight/catalog_helper_behavior.rb +48 -28
  27. data/app/helpers/blacklight/facets_helper_behavior.rb +9 -75
  28. data/app/models/record_mailer.rb +1 -16
  29. data/app/views/bookmarks/index.html.erb +2 -0
  30. data/app/views/catalog/_bookmark_control.html.erb +3 -4
  31. data/app/views/catalog/_document.html.erb +2 -1
  32. data/app/views/catalog/_document_header.html.erb +6 -3
  33. data/app/views/catalog/_email_form.html.erb +0 -7
  34. data/app/views/catalog/_facet_layout.html.erb +1 -1
  35. data/app/views/catalog/_group_default.html.erb +12 -0
  36. data/app/views/catalog/_index_default.html.erb +1 -1
  37. data/app/views/catalog/_opensearch_response_metadata.html.erb +2 -3
  38. data/app/views/catalog/_paginate_compact.html.erb +2 -2
  39. data/app/views/catalog/_results_pagination.html.erb +2 -2
  40. data/app/views/catalog/_search_form.html.erb +1 -1
  41. data/app/views/catalog/_sms_form.html.erb +1 -21
  42. data/app/views/catalog/_thumbnail_default.html.erb +5 -0
  43. data/app/views/catalog/email_sent.html.erb +9 -0
  44. data/app/views/catalog/index.atom.builder +7 -8
  45. data/app/views/catalog/index.html.erb +6 -3
  46. data/app/views/catalog/librarian_view.html.erb +1 -1
  47. data/app/views/catalog/sms_sent.html.erb +9 -0
  48. data/app/views/feedback/complete.html.erb +2 -0
  49. data/app/views/feedback/show.html.erb +7 -5
  50. data/app/views/kaminari/blacklight_compact/_paginator.html.erb +1 -1
  51. data/app/views/layouts/blacklight.html.erb +1 -2
  52. data/app/views/saved_searches/index.html.erb +2 -0
  53. data/app/views/search_history/index.html.erb +1 -1
  54. data/blacklight.gemspec +1 -1
  55. data/config/locales/blacklight.en.yml +11 -0
  56. data/config/locales/blacklight.fr.yml +15 -1
  57. data/gemfiles/rails3.gemfile +7 -0
  58. data/gemfiles/rails4.gemfile +7 -0
  59. data/lib/blacklight.rb +1 -0
  60. data/lib/blacklight/catalog.rb +101 -56
  61. data/lib/blacklight/configuration.rb +1 -1
  62. data/lib/blacklight/controller.rb +7 -4
  63. data/lib/blacklight/facet.rb +79 -0
  64. data/lib/blacklight/routes.rb +0 -1
  65. data/lib/blacklight/solr/document.rb +4 -0
  66. data/lib/blacklight/solr/document/marc_export.rb +1 -1
  67. data/lib/blacklight/solr_helper.rb +39 -8
  68. data/lib/blacklight/solr_response.rb +35 -3
  69. data/lib/blacklight/solr_response/facets.rb +4 -0
  70. data/lib/blacklight/solr_response/group.rb +33 -0
  71. data/lib/blacklight/solr_response/group_response.rb +49 -0
  72. data/lib/blacklight/solr_response/pagination_methods.rb +27 -0
  73. data/lib/blacklight/user.rb +30 -32
  74. data/lib/generators/blacklight/assets_generator.rb +3 -1
  75. data/lib/generators/blacklight/blacklight_generator.rb +28 -125
  76. data/lib/generators/blacklight/marc_generator.rb +66 -0
  77. data/lib/generators/blacklight/models_generator.rb +113 -0
  78. data/lib/generators/blacklight/templates/alternate_controller.rb +9 -0
  79. data/lib/generators/blacklight/templates/config/solr.yml +0 -2
  80. data/lib/generators/blacklight/templates/solr_document.rb +1 -13
  81. data/lib/railties/all_tests.rake +5 -8
  82. data/spec/controllers/catalog_controller_spec.rb +185 -113
  83. data/spec/features/alternate_controller_spec.rb +34 -0
  84. data/spec/features/bookmarks_spec.rb +58 -0
  85. data/spec/features/did_you_mean_spec.rb +135 -0
  86. data/spec/features/librarian_view_spec.rb +13 -0
  87. data/spec/features/record_view_spec.rb +37 -0
  88. data/spec/features/saved_searches_spec.rb +47 -0
  89. data/spec/features/search_filters_spec.rb +137 -0
  90. data/spec/features/search_history_spec.rb +75 -0
  91. data/spec/features/search_pagination_spec.rb +91 -0
  92. data/spec/features/search_results_spec.rb +68 -0
  93. data/spec/features/search_sort_spec.rb +20 -0
  94. data/spec/features/search_spec.rb +108 -0
  95. data/spec/helpers/blacklight_helper_spec.rb +45 -2
  96. data/spec/helpers/catalog_helper_spec.rb +134 -1
  97. data/spec/helpers/facets_helper_spec.rb +8 -0
  98. data/spec/lib/blacklight/solr_response/group_response_spec.rb +78 -0
  99. data/spec/lib/blacklight/solr_response/group_spec.rb +70 -0
  100. data/spec/lib/blacklight_solr_response_spec.rb +11 -5
  101. data/spec/lib/blacklight_user_spec.rb +22 -41
  102. data/spec/lib/solr_helper_spec.rb +73 -1
  103. data/spec/models/record_mailer_spec.rb +3 -3
  104. data/spec/models/{solr_docment_spec.rb → solr_document_spec.rb} +1 -1
  105. data/spec/spec_helper.rb +0 -1
  106. data/spec/support/features.rb +7 -0
  107. data/spec/support/features/session_helpers.rb +22 -0
  108. data/spec/test_app_templates/Gemfile.extra +0 -4
  109. data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -6
  110. data/spec/test_app_templates/lib/tasks/blacklight_test_app.rake +1 -9
  111. data/spec/views/catalog/_facets.html.erb_spec.rb +2 -1
  112. data/tasks/blacklight.rake +0 -10
  113. metadata +49 -58
  114. data/features/bookmarks.feature +0 -68
  115. data/features/did_you_mean.feature +0 -123
  116. data/features/librarian_view.feature +0 -18
  117. data/features/record_view.feature +0 -40
  118. data/features/saved_searches.feature +0 -49
  119. data/features/search.feature +0 -83
  120. data/features/search_filters.feature +0 -119
  121. data/features/search_history.feature +0 -85
  122. data/features/search_pagination.feature +0 -53
  123. data/features/search_results.feature +0 -61
  124. data/features/search_sort.feature +0 -27
  125. data/features/step_definitions/bookmarks_steps.rb +0 -6
  126. data/features/step_definitions/error_steps.rb +0 -5
  127. data/features/step_definitions/general_steps.rb +0 -50
  128. data/features/step_definitions/record_view_steps.rb +0 -12
  129. data/features/step_definitions/saved_searches_steps.rb +0 -19
  130. data/features/step_definitions/search_facets_steps.rb +0 -29
  131. data/features/step_definitions/search_history_steps.rb +0 -9
  132. data/features/step_definitions/search_pagination_steps.rb +0 -29
  133. data/features/step_definitions/search_result_steps.rb +0 -115
  134. data/features/step_definitions/search_steps.rb +0 -118
  135. data/features/step_definitions/user_steps.rb +0 -5
  136. data/features/step_definitions/web_steps.rb +0 -217
  137. data/features/support/env.rb +0 -65
  138. data/features/support/paths.rb +0 -48
  139. data/features/support/selectors.rb +0 -40
  140. data/lib/railties/blacklight_cucumber.rake +0 -126
  141. 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
- s.user_id = current_user.id
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
- b.user_id = current_user.id
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
@@ -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
 
@@ -109,6 +109,10 @@ module Blacklight::Solr::Document
109
109
  id
110
110
  end
111
111
 
112
+ def as_json(options = nil)
113
+ @_source.as_json(options)
114
+ end
115
+
112
116
  def to_partial_path
113
117
  'catalog/document'
114
118
  end
@@ -94,7 +94,7 @@ module Blacklight::Solr::Document::MarcExport
94
94
  export_text << "&amp;rft.pub=" + ((publisher_info.nil? or publisher_info['b'].nil?) ? "" : CGI::escape(publisher_info['b']))
95
95
  export_text << "&amp;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-Z$_\-\^]+$/
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
- solr_parameters[:'facet.field'][idx] = "{!ex=#{facet.ex}}#{solr_parameters[:'facet.field'][idx]}" unless idx.nil?
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
- document_list = solr_response.docs.collect {|doc| SolrDocument.new(doc, solr_response)}
373
- return [solr_response, document_list]
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']
@@ -20,6 +20,10 @@ module Blacklight::SolrResponse::Facets
20
20
  def label
21
21
  super || value
22
22
  end
23
+
24
+ def as_json(props = nil)
25
+ table.as_json(props)
26
+ end
23
27
  end
24
28
 
25
29
  # represents a facet; which is a field and its values
@@ -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
@@ -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.send :has_many, :bookmarks, :dependent => :destroy, :as => :user
10
- base.send :has_many, :searches, :dependent => :destroy, :as => :user
11
- base.send :include, InstanceMethods
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
- # The following methods will be included in any active model object
15
- # that calls "is_blacklight_user"
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
- def has_bookmarks?
19
- bookmarks.count > 0
20
- end
21
+ def has_bookmarks?
22
+ bookmarks.any?
23
+ end
21
24
 
22
- def has_searches?
23
- searches.count > 0
24
- end
25
+ def has_searches?
26
+ searches.any?
27
+ end
25
28
 
26
- def bookmarked_document_ids
27
- self.bookmarks.map{|bm|bm.document_id}
28
- end
29
+ def bookmarked_document_ids
30
+ self.bookmarks.pluck(:document_id)
31
+ end
29
32
 
30
- # see #current_bookmark_for, is easier
31
- def document_is_bookmarked?(document_id)
32
- bookmarked_document_ids.include? document_id
33
- end
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
- # returns a Bookmark object if there is one for document_id, else
36
- # nil.
37
- def existing_bookmark_for(document_id)
38
- # to_a, we don't want to go to the database, we want to use cached
39
- # copy.
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
- def documents_to_bookmark=(docs)
44
- docs.each do |doc|
45
- self.bookmarks.create(doc) unless bookmarked_document_ids.include?(doc[:document_id])
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