blacklight 3.8.2 → 4.0.0.pre6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. data/Gemfile +1 -0
  2. data/README.md +1 -1
  3. data/VERSION +1 -1
  4. data/app/assets/javascripts/blacklight/blacklight.js +12 -1
  5. data/app/assets/javascripts/blacklight/bootstrap_dropdowns.js +3 -0
  6. data/app/assets/javascripts/blacklight/checkbox_submit.js +12 -5
  7. data/app/assets/javascripts/blacklight/core.js +0 -1
  8. data/app/assets/javascripts/blacklight/css_dropdowns.js +10 -0
  9. data/app/assets/javascripts/blacklight/facet_expand_contract.js +5 -5
  10. data/app/assets/javascripts/blacklight/lightbox_dialog.js +68 -13
  11. data/app/assets/javascripts/blacklight/select_submit.js +19 -10
  12. data/app/assets/javascripts/improved-modal/bootstrap-modal.js +282 -0
  13. data/app/assets/javascripts/improved-modal/bootstrap-modalmanager.js +353 -0
  14. data/app/assets/stylesheets/blacklight/_blacklight_base.css.scss +16 -5
  15. data/app/assets/stylesheets/blacklight/_bookmark.css.scss +24 -6
  16. data/app/assets/stylesheets/blacklight/_catalog.css.scss +115 -141
  17. data/app/assets/stylesheets/blacklight/_dropdown.css.scss +57 -0
  18. data/app/assets/stylesheets/blacklight/_facets.css.scss +127 -58
  19. data/app/assets/stylesheets/blacklight/_footer.css.scss +20 -0
  20. data/app/assets/stylesheets/blacklight/_header.css.scss +90 -21
  21. data/app/assets/stylesheets/blacklight/_layout.css.scss +10 -9
  22. data/app/assets/stylesheets/blacklight/_modal.css.scss +23 -0
  23. data/app/assets/stylesheets/blacklight/_print.css.scss +0 -7
  24. data/app/assets/stylesheets/blacklight/_responsive.css.scss +3 -0
  25. data/app/assets/stylesheets/blacklight/_search_history.css.scss +2 -4
  26. data/app/assets/stylesheets/blacklight/blacklight.css.scss +0 -1
  27. data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +9 -2
  28. data/app/assets/stylesheets/blacklight/responsive_partials/_catalog.css.scss +5 -0
  29. data/app/assets/stylesheets/blacklight/responsive_partials/_facets.css.scss +37 -0
  30. data/app/assets/stylesheets/blacklight/responsive_partials/_header.css.scss +30 -0
  31. data/app/assets/stylesheets/improved-modal/bootstrap-modal.css +199 -0
  32. data/app/controllers/bookmarks_controller.rb +16 -10
  33. data/app/helpers/blacklight/blacklight_helper_behavior.rb +124 -61
  34. data/app/helpers/blacklight/catalog_helper_behavior.rb +5 -3
  35. data/app/helpers/blacklight/facets_helper_behavior.rb +9 -9
  36. data/app/views/_flash_msg.html.erb +9 -4
  37. data/app/views/_user_util_links.html.erb +23 -17
  38. data/app/views/bookmarks/_tools.html.erb +7 -7
  39. data/app/views/bookmarks/index.html.erb +5 -13
  40. data/app/views/catalog/_bookmark_control.html.erb +2 -4
  41. data/app/views/catalog/_bookmark_form.html.erb +1 -1
  42. data/app/views/catalog/_citation.html.erb +21 -20
  43. data/app/views/catalog/_constraints.html.erb +8 -6
  44. data/app/views/catalog/_document_header.html.erb +6 -7
  45. data/app/views/catalog/_document_list.html.erb +1 -7
  46. data/app/views/catalog/_email_form.html.erb +42 -16
  47. data/app/views/catalog/_facet_layout.html.erb +1 -1
  48. data/app/views/catalog/_facet_limit.html.erb +1 -1
  49. data/app/views/catalog/_facet_pagination.html.erb +11 -14
  50. data/app/views/catalog/_facets.html.erb +16 -2
  51. data/app/views/catalog/_home.html.erb +2 -2
  52. data/app/views/catalog/_home_text.html.erb +5 -2
  53. data/app/views/catalog/_index_default.html.erb +2 -2
  54. data/app/views/catalog/_marc_view.html.erb +0 -1
  55. data/app/views/catalog/_paginate_compact.html.erb +5 -0
  56. data/app/views/catalog/_per_page_widget.html.erb +13 -7
  57. data/app/views/catalog/_previous_next_doc.html.erb +14 -4
  58. data/app/views/catalog/_refworks_form.html.erb +2 -2
  59. data/app/views/catalog/_results_pagination.html.erb +4 -1
  60. data/app/views/catalog/_search_form.html.erb +19 -13
  61. data/app/views/catalog/_show_default.html.erb +2 -2
  62. data/app/views/catalog/_show_more_like_this.html.erb +3 -0
  63. data/app/views/catalog/_show_sidebar.html.erb +14 -1
  64. data/app/views/catalog/_show_tools.html.erb +18 -18
  65. data/app/views/catalog/_sms_form.html.erb +35 -10
  66. data/app/views/catalog/_sort_and_per_page.html.erb +5 -3
  67. data/app/views/catalog/_sort_widget.html.erb +12 -6
  68. data/app/views/catalog/citation.html.erb +1 -1
  69. data/app/views/catalog/citation.js.erb +7 -0
  70. data/app/views/catalog/email.html.erb +5 -0
  71. data/app/views/catalog/facet.html.erb +28 -21
  72. data/app/views/catalog/index.html.erb +26 -26
  73. data/app/views/catalog/librarian_view.html.erb +7 -0
  74. data/app/views/catalog/show.html.erb +35 -29
  75. data/app/views/catalog/sms.html.erb +5 -0
  76. data/app/views/kaminari/blacklight/_first_page.html.erb +2 -2
  77. data/app/views/kaminari/blacklight/_gap.html.erb +4 -1
  78. data/app/views/kaminari/blacklight/_last_page.html.erb +2 -2
  79. data/app/views/kaminari/blacklight/_next_page.html.erb +3 -3
  80. data/app/views/kaminari/blacklight/_page.html.erb +4 -3
  81. data/app/views/kaminari/blacklight/_paginator.html.erb +5 -5
  82. data/app/views/kaminari/blacklight/_prev_page.html.erb +3 -3
  83. data/app/views/kaminari/blacklight_compact/_next_page.html.erb +9 -0
  84. data/app/views/kaminari/blacklight_compact/_paginator.html.erb +15 -0
  85. data/app/views/kaminari/blacklight_compact/_prev_page.html.erb +9 -0
  86. data/app/views/layouts/blacklight.html.erb +47 -27
  87. data/app/views/saved_searches/index.html.erb +2 -2
  88. data/app/views/search_history/index.html.erb +12 -7
  89. data/app/views/shared/_footer.html.erb +0 -0
  90. data/app/views/shared/_header_navbar.html.erb +25 -0
  91. data/blacklight.gemspec +2 -5
  92. data/config/locales/blacklight.en.yml +23 -15
  93. data/lib/blacklight.rb +2 -2
  94. data/lib/blacklight/catalog.rb +36 -14
  95. data/lib/blacklight/configuration.rb +10 -2
  96. data/lib/blacklight/mash.rb +151 -0
  97. data/lib/blacklight/solr/document.rb +73 -11
  98. data/lib/blacklight/solr/document/extensions.rb +0 -8
  99. data/lib/blacklight/solr/document/marc_export.rb +7 -2
  100. data/lib/blacklight/solr/document/more_like_this.rb +5 -0
  101. data/lib/blacklight/solr_helper.rb +43 -18
  102. data/lib/blacklight/solr_response.rb +60 -0
  103. data/lib/blacklight/solr_response/facets.rb +58 -0
  104. data/lib/blacklight/solr_response/more_like_this.rb +14 -0
  105. data/lib/blacklight/solr_response/spelling.rb +92 -0
  106. data/lib/generators/blacklight/assets_generator.rb +1 -14
  107. data/lib/generators/blacklight/blacklight_generator.rb +22 -21
  108. data/lib/generators/blacklight/jetty_generator.rb +1 -35
  109. data/{test_support → lib/generators/blacklight/templates}/alternate_controller.rb +0 -0
  110. data/lib/generators/blacklight/templates/blacklight.css.scss +4 -0
  111. data/lib/generators/blacklight/templates/config/SolrMarc/config-test.properties +2 -2
  112. data/lib/generators/blacklight/templates/config/jetty.yml +6 -0
  113. data/lib/generators/blacklight/test_support_generator.rb +35 -0
  114. data/lib/railties/all_tests.rake +5 -23
  115. data/lib/railties/blacklight_cucumber.rake +2 -11
  116. data/lib/railties/blacklight_rspec.rake +2 -12
  117. data/test_support/bin/run-tests.sh +1 -1
  118. data/test_support/bin/setup-test-app.sh +123 -0
  119. data/test_support/bin/test.sh +21 -21
  120. data/test_support/features/bookmarks.feature +9 -3
  121. data/test_support/features/saved_searches.feature +3 -3
  122. data/test_support/features/search.feature +3 -3
  123. data/test_support/features/search_filters.feature +24 -26
  124. data/test_support/features/search_history.feature +9 -10
  125. data/test_support/features/search_sort.feature +4 -6
  126. data/test_support/features/step_definitions/general_steps.rb +0 -4
  127. data/test_support/features/step_definitions/search_result_steps.rb +2 -1
  128. data/test_support/features/step_definitions/search_steps.rb +32 -2
  129. data/test_support/spec/controllers/application_controller_spec.rb +8 -0
  130. data/test_support/spec/controllers/catalog_controller_spec.rb +3 -18
  131. data/test_support/spec/helpers/blacklight_helper_spec.rb +116 -20
  132. data/test_support/spec/helpers/catalog_helper_spec.rb +14 -6
  133. data/test_support/spec/helpers/facets_helper_spec.rb +1 -1
  134. data/test_support/spec/lib/blacklight_solr_document_more_like_this_spec.rb +18 -0
  135. data/test_support/spec/lib/blacklight_solr_document_spec.rb +54 -1
  136. data/test_support/spec/lib/blacklight_solr_response_spec.rb +153 -0
  137. data/test_support/spec/lib/facet_paginator_spec.rb +1 -1
  138. data/test_support/spec/lib/marc_export_spec.rb +14 -6
  139. data/test_support/spec/lib/solr_helper_spec.rb +22 -6
  140. data/test_support/spec/models/solr_docment_spec.rb +1 -4
  141. data/test_support/spec/{features → requests}/alternate_controller_spec.rb +3 -2
  142. data/test_support/spec/views/catalog/_facets.html.erb_spec.rb +20 -4
  143. data/test_support/spec/views/catalog/_show_sidebar.erb_spec.rb +25 -0
  144. metadata +53 -131
  145. data/app/assets/javascripts/blacklight/more_facets.js +0 -16
  146. data/app/assets/javascripts/jquery-1.4.2.min.js +0 -154
  147. data/app/assets/javascripts/jquery-ui-1.8.1.custom.min.js +0 -756
  148. data/app/assets/javascripts/jquery.uiExt.ajaxyDialog.js +0 -180
  149. data/app/assets/stylesheets/blacklight/_formatting.css.scss +0 -164
  150. data/app/assets/stylesheets/blacklight/grids/_susy_grid.css.scss +0 -72
  151. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-anim_basic_16x16.gif +0 -0
  152. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  153. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  154. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  155. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  156. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  157. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  158. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-bg_gloss-wave_35_558fd0_500x100.png +0 -0
  159. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  160. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  161. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  162. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  163. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-icons_2e4f81_256x240.png +0 -0
  164. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  165. data/app/assets/stylesheets/jquery/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  166. data/app/assets/stylesheets/jquery/ui-lightness/jquery-ui-1.8.1.custom.css +0 -486
  167. data/app/models/solr_document.rb +0 -5
  168. data/app/views/catalog/email.erb +0 -1
  169. data/app/views/catalog/sms.erb +0 -1
  170. data/doc/Atom-Responses.md +0 -90
  171. data/doc/Blacklight-3.2-Release-Notes-and-Upgrade-Guide.md +0 -191
  172. data/doc/Blacklight-3.3-release-notes-and-upgrade-guide.md +0 -37
  173. data/doc/Blacklight-3.4-release-notes-and-upgrade-guide.md +0 -27
  174. data/doc/Blacklight-3.5-release-notes-and-upgrade-guide.md +0 -44
  175. data/doc/Blacklight-3.6-release-notes-and-upgrade-guide.md +0 -25
  176. data/doc/Blacklight-3.7-release-notes-and-upgrade-guide.md +0 -78
  177. data/doc/Blacklight-3.8-release-notes-and-upgrade-guide.md +0 -11
  178. data/doc/Blacklight-Add-ons.md +0 -28
  179. data/doc/Blacklight-configuration.md +0 -301
  180. data/doc/Blacklight-on-Heroku.md +0 -135
  181. data/doc/Community-principles.md +0 -44
  182. data/doc/Configuring-and-Customizing-Blacklight.md +0 -271
  183. data/doc/Contributing-to-Blacklight.md +0 -25
  184. data/doc/Examples.md +0 -62
  185. data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -141
  186. data/doc/Home.md +0 -77
  187. data/doc/How-to-release-a-version.md +0 -37
  188. data/doc/Indexing-your-data-into-solr.md +0 -5
  189. data/doc/Integration-with-Rails-Footnotes.md +0 -20
  190. data/doc/Pagination.md +0 -38
  191. data/doc/Providing-your-own-view-templates.md +0 -109
  192. data/doc/Quickstart.md +0 -116
  193. data/doc/README.md +0 -77
  194. data/doc/README_SOLR.md +0 -245
  195. data/doc/Release-Notes-And-Upgrade-Guides.md +0 -14
  196. data/doc/Sunspot-for-indexing.md +0 -46
  197. data/doc/User-Authentication.md +0 -60
  198. data/doc/testing.md +0 -115
  199. data/lib/generators/blacklight/solr_conf_generator.rb +0 -26
  200. data/lib/generators/blacklight/templates/assets/standard.css.scss +0 -59
  201. data/lib/generators/blacklight/templates/config/blacklight_config.rb +0 -3
  202. data/lib/generators/blacklight/templates/config/compass.rb +0 -2
  203. data/lib/generators/blacklight/templates/solr_conf/schema.xml +0 -689
  204. data/lib/generators/blacklight/templates/solr_conf/solrconfig.xml +0 -1846
  205. data/lib/solrmarc.log.1 +0 -849
  206. data/test_support/spec/controllers/bookmarks_controller_spec.rb +0 -48
data/lib/blacklight.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require 'kaminari'
3
3
  require 'rsolr'
4
- require 'rsolr-ext'
5
4
 
6
5
  module Blacklight
7
6
 
@@ -24,6 +23,7 @@ module Blacklight
24
23
  autoload :Routes, 'blacklight/routes'
25
24
 
26
25
  autoload :OpenStructWithHashAccess, 'blacklight/utils'
26
+ autoload :SolrResponse, 'blacklight/solr_response'
27
27
 
28
28
  extend SearchFields
29
29
 
@@ -48,7 +48,7 @@ module Blacklight
48
48
  end
49
49
 
50
50
  def self.solr
51
- @solr ||= RSolr::Ext.connect(Blacklight.solr_config)
51
+ @solr ||= RSolr.connect(Blacklight.solr_config)
52
52
  end
53
53
 
54
54
  def self.solr_config
@@ -73,6 +73,11 @@ module Blacklight::Catalog
73
73
  # displays values and pagination links for a single facet field
74
74
  def facet
75
75
  @pagination = get_facet_pagination(params[:id], params)
76
+
77
+ respond_to do |format|
78
+ format.html
79
+ format.js { render :layout => false }
80
+ end
76
81
  end
77
82
 
78
83
  # method to serve up XML OpenSearch description and JSON autocomplete response
@@ -111,11 +116,22 @@ module Blacklight::Catalog
111
116
  else
112
117
  flash[:error] = I18n.t('blacklight.email.errors.to.invalid', :to => params[:to])
113
118
  end
114
- email.deliver unless flash[:error]
115
- redirect_to :back
116
119
  else
117
120
  flash[:error] = I18n.t('blacklight.email.errors.to.blank')
118
121
  end
122
+
123
+ unless flash[:error]
124
+ email.deliver
125
+ flash[:success] = "Email sent"
126
+ redirect_to catalog_path(params['id']) unless request.xhr?
127
+ end
128
+ end
129
+
130
+ unless !request.xhr? && flash[:success]
131
+ respond_to do |format|
132
+ format.js { render :layout => false }
133
+ format.html
134
+ end
119
135
  end
120
136
  end
121
137
 
@@ -133,30 +149,36 @@ module Blacklight::Catalog
133
149
  else
134
150
  email = RecordMailer.sms_record(@documents, {:to => phone_num, :carrier => params[:carrier]}, url_gen_params)
135
151
  end
136
- email.deliver unless flash[:error]
137
- redirect_to :back
152
+
138
153
  else
139
154
  flash[:error] = I18n.t('blacklight.sms.errors.carrier.blank')
140
155
  end
141
156
  else
142
157
  flash[:error] = I18n.t('blacklight.sms.errors.to.blank')
143
158
  end
159
+
160
+ unless flash[:error]
161
+ email.deliver
162
+ flash[:success] = "SMS sent"
163
+ redirect_to catalog_path(params['id']) unless request.xhr?
164
+ end
165
+ end
144
166
 
167
+ unless !request.xhr? && flash[:success]
168
+ respond_to do |format|
169
+ format.js { render :layout => false }
170
+ format.html
171
+ end
145
172
  end
146
173
  end
147
174
 
148
- # DEPRECATED backwards compatible method that will just redirect to the appropriate action. It will return a 404 if a bad action is supplied (just in case).
149
- def send_email_record
150
- warn "[DEPRECATION] CatalogController#send_email_record is deprecated. Please use the email or sms controller action instead."
151
- if ["sms","email"].include?(params[:style])
152
- redirect_to :action => params[:style]
153
- else
154
- render :file => "#{::Rails.root}/public/404.html", :layout => false, :status => 404
155
- end
156
- end
157
-
158
175
  def librarian_view
159
176
  @response, @document = get_solr_response_for_doc_id
177
+
178
+ respond_to do |format|
179
+ format.html
180
+ format.js { render :layout => false }
181
+ end
160
182
  end
161
183
 
162
184
 
@@ -12,7 +12,8 @@ module Blacklight
12
12
  unique_key = ((SolrDocument.unique_key if defined?(SolrDocument)) || 'id')
13
13
 
14
14
  {
15
- :solr_request_handler => 'select',
15
+ :solr_path => 'select',
16
+ :qt => 'search',
16
17
  :default_solr_params => {},
17
18
  :document_solr_request_handler => nil,
18
19
  :default_document_solr_params => {},
@@ -21,12 +22,14 @@ module Blacklight
21
22
  :spell_max => 5,
22
23
  :max_per_page => 100,
23
24
  :per_page => [10,20,50,100],
24
- :add_facet_fields_to_solr_request => false
25
+ :add_facet_fields_to_solr_request => false,
26
+ :add_field_configuration_to_solr_request => false
25
27
  }
26
28
  end
27
29
  end
28
30
  end
29
31
 
32
+
30
33
  # XXX this isn't very pretty, but it works.
31
34
  require 'blacklight/configuration/fields'
32
35
  require 'blacklight/configuration/solr_field'
@@ -82,6 +85,11 @@ module Blacklight
82
85
  self.add_facet_fields_to_solr_request = true
83
86
  end
84
87
 
88
+ # Add any configured facet fields to the default solr parameters hash
89
+ def add_field_configuration_to_solr_request!
90
+ self.add_field_configuration_to_solr_request = true
91
+ end
92
+
85
93
  def facet_fields_to_add_to_solr
86
94
  return facet_fields.reject { |k,v| v[:query] }.map { |k,v| v.field } if self.add_facet_fields_to_solr_request
87
95
 
@@ -0,0 +1,151 @@
1
+ # This class has dubious semantics and we only have it so that people can write
2
+ # params[:key] instead of params['key'].
3
+ class Mash < Hash
4
+
5
+ # @param constructor<Object>
6
+ # The default value for the mash. Defaults to an empty hash.
7
+ #
8
+ # @details [Alternatives]
9
+ # If constructor is a Hash, a new mash will be created based on the keys of
10
+ # the hash and no default value will be set.
11
+ def initialize(constructor = {})
12
+ if constructor.is_a?(Hash)
13
+ super()
14
+ update(constructor)
15
+ else
16
+ super(constructor)
17
+ end
18
+ end
19
+
20
+ # @param key<Object> The default value for the mash. Defaults to nil.
21
+ #
22
+ # @details [Alternatives]
23
+ # If key is a Symbol and it is a key in the mash, then the default value will
24
+ # be set to the value matching the key.
25
+ def default(key = nil)
26
+ if key.is_a?(Symbol) && include?(key = key.to_s)
27
+ self[key]
28
+ else
29
+ super
30
+ end
31
+ end
32
+
33
+ alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
34
+ alias_method :regular_update, :update unless method_defined?(:regular_update)
35
+
36
+ # @param key<Object> The key to set.
37
+ # @param value<Object>
38
+ # The value to set the key to.
39
+ #
40
+ # @see Mash#convert_key
41
+ # @see Mash#convert_value
42
+ def []=(key, value)
43
+ regular_writer(convert_key(key), convert_value(value))
44
+ end
45
+
46
+ # @param other_hash<Hash>
47
+ # A hash to update values in the mash with. The keys and the values will be
48
+ # converted to Mash format.
49
+ #
50
+ # @return <Mash> The updated mash.
51
+ def update(other_hash)
52
+ other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
53
+ self
54
+ end
55
+
56
+ alias_method :merge!, :update
57
+
58
+ # @param key<Object> The key to check for. This will be run through convert_key.
59
+ #
60
+ # @return <TrueClass, FalseClass> True if the key exists in the mash.
61
+ def key?(key)
62
+ super(convert_key(key))
63
+ end
64
+
65
+ # def include? def has_key? def member?
66
+ alias_method :include?, :key?
67
+ alias_method :has_key?, :key?
68
+ alias_method :member?, :key?
69
+
70
+ # @param key<Object> The key to fetch. This will be run through convert_key.
71
+ # @param *extras<Array> Default value.
72
+ #
73
+ # @return <Object> The value at key or the default value.
74
+ def fetch(key, *extras)
75
+ super(convert_key(key), *extras)
76
+ end
77
+
78
+ # @param *indices<Array>
79
+ # The keys to retrieve values for. These will be run through +convert_key+.
80
+ #
81
+ # @return <Array> The values at each of the provided keys
82
+ def values_at(*indices)
83
+ indices.collect {|key| self[convert_key(key)]}
84
+ end
85
+
86
+ # @return <Mash> A duplicate of this mash.
87
+ def dup
88
+ Mash.new(self)
89
+ end
90
+
91
+ # @param hash<Hash> The hash to merge with the mash.
92
+ #
93
+ # @return <Mash> A new mash with the hash values merged in.
94
+ def merge(hash)
95
+ self.dup.update(hash)
96
+ end
97
+
98
+ # @param key<Object>
99
+ # The key to delete from the mash.\
100
+ def delete(key)
101
+ super(convert_key(key))
102
+ end
103
+
104
+ # Used to provide the same interface as Hash.
105
+ #
106
+ # @return <Mash> This mash unchanged.
107
+ def stringify_keys!; self end
108
+
109
+ # @return <Hash> The mash as a Hash with string keys.
110
+ def to_hash
111
+ Hash.new(default).merge(self)
112
+ end
113
+
114
+ protected
115
+ # @param key<Object> The key to convert.
116
+ #
117
+ # @param <Object>
118
+ # The converted key. If the key was a symbol, it will be converted to a
119
+ # string.
120
+ #
121
+ # @api private
122
+ def convert_key(key)
123
+ key.kind_of?(Symbol) ? key.to_s : key
124
+ end
125
+
126
+ # @param value<Object> The value to convert.
127
+ #
128
+ # @return <Object>
129
+ # The converted value. A Hash or an Array of hashes, will be converted to
130
+ # their Mash equivalents.
131
+ #
132
+ # @api private
133
+ def convert_value(value)
134
+ case value
135
+ when Hash
136
+ value.to_mash
137
+ when Array
138
+ value.collect { |e| convert_value(e) }
139
+ else
140
+ value
141
+ end
142
+ end
143
+ end
144
+
145
+ unless Hash.respond_to?(:to_mash)
146
+ class Hash
147
+ def to_mash
148
+ Mash.new(self)
149
+ end
150
+ end
151
+ end
@@ -1,6 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require 'rsolr'
3
- require 'rsolr-ext'
4
3
  ##
5
4
  ##
6
5
  # = Introduction
@@ -10,8 +9,7 @@ require 'rsolr-ext'
10
9
  # provided for you which is pretty much a blank class "include"ing
11
10
  # Blacklight::Solr::Document.
12
11
  #
13
- # Blacklight::Solr::Document mixes in Rsolr::Ext::Model to the calling class.
14
- # It also provides some DefaultFinders.
12
+ # Blacklight::Solr::Document provides some DefaultFinders.
15
13
  #
16
14
  # It also provides support for Document Extensions, which advertise supported
17
15
  # transformation formats.
@@ -25,28 +23,92 @@ module Blacklight::Solr::Document
25
23
  autoload :Sms, 'blacklight/solr/document/sms'
26
24
  autoload :Extensions, 'blacklight/solr/document/extensions'
27
25
  autoload :Export, 'blacklight/solr/document/export'
26
+ autoload :MoreLikeThis, 'blacklight/solr/document/more_like_this'
28
27
 
29
28
  extend ActiveSupport::Concern
30
29
  include Blacklight::Solr::Document::Export
30
+ include Blacklight::Solr::Document::MoreLikeThis
31
31
 
32
32
  included do
33
33
  extend ActiveModel::Naming
34
- include RSolr::Ext::Model
35
- include RSolrExtOverrides
36
34
  include Blacklight::Solr::Document::Extensions
37
-
38
35
  end
39
36
 
40
- module RSolrExtOverrides
41
- def id
42
- self[self.class.unique_key]
37
+ attr_reader :solr_response
38
+
39
+ def initialize(source_doc={}, solr_response=nil)
40
+ @_source = source_doc.with_indifferent_access
41
+ @solr_response = solr_response
42
+ apply_extensions
43
+ end
44
+
45
+ # the wrapper method to the @_source object.
46
+ # If a method is missing, it gets sent to @_source
47
+ # with all of the original params and block
48
+ def method_missing(m, *args, &b)
49
+ @_source.send(m, *args, &b)
50
+ end
51
+
52
+ def [] *args
53
+ @_source.send :[], *args
54
+ end
55
+
56
+ # Helper method to check if value/multi-values exist for a given key.
57
+ # The value can be a string, or a RegExp
58
+ # Multiple "values" can be given; only one needs to match.
59
+ #
60
+ # Example:
61
+ # doc.has?(:location_facet)
62
+ # doc.has?(:location_facet, 'Clemons')
63
+ # doc.has?(:id, 'h009', /^u/i)
64
+ def has?(k, *values)
65
+ return if @_source[k].nil?
66
+ return true if @_source.key?(k) and values.empty?
67
+ target = @_source[k]
68
+ if target.is_a?(Array)
69
+ values.each do |val|
70
+ return target.any?{|tv| val.is_a?(Regexp) ? (tv =~ val) : (tv==val)}
71
+ end
72
+ else
73
+ return values.any? {|val| val.is_a?(Regexp) ? (target =~ val) : (target == val)}
43
74
  end
75
+ end
44
76
 
45
- def to_param
46
- id
77
+ def has_highlight_field? k
78
+ return false if @solr_response['highlighting'].blank? or @solr_response['highlighting'][self.id].blank?
79
+
80
+ @solr_response['highlighting'][self.id].key? k.to_s
81
+ end
82
+
83
+ def highlight_field k
84
+ return nil unless has_highlight_field? k
85
+ @solr_response['highlighting'][self.id][k.to_s].map { |x| x.html_safe }
86
+
87
+ end
88
+
89
+ # helper
90
+ # key is the name of the field
91
+ # opts is a hash with the following valid keys:
92
+ # - :sep - a string used for joining multivalued field values
93
+ # - :default - a value to return when the key doesn't exist
94
+ # if :sep is nil and the field is a multivalued field, the array is returned
95
+ def get(key, opts={:sep=>', ', :default=>nil})
96
+ if @_source.key? key
97
+ val = @_source[key]
98
+ (val.is_a?(Array) and opts[:sep]) ? val.join(opts[:sep]) : val
99
+ else
100
+ opts[:default]
47
101
  end
48
102
  end
49
103
 
104
+ def id
105
+ self[self.class.unique_key]
106
+ end
107
+
108
+ def to_param
109
+ id
110
+ end
111
+
50
112
  def to_partial_path
51
113
  'catalog/document'
52
114
  end
@@ -20,14 +20,6 @@
20
20
  module Blacklight::Solr::Document::Extensions
21
21
  extend ActiveSupport::Concern
22
22
 
23
- included do
24
- # after_initialize hook comes from RSolr::Ext::Model, I think.
25
- # We need to make sure all extensions get applied.
26
- after_initialize do
27
- apply_extensions
28
- end
29
- end
30
-
31
23
  # Needs to be called in initializer of class including this module, to
32
24
  # apply all registered extensions on a per-document basis
33
25
  def apply_extensions
@@ -134,8 +134,13 @@ module Blacklight::Solr::Document::MarcExport
134
134
  java_import java.text.Normalizer
135
135
  Normalizer.normalize(text, Normalizer::Form::NFC).to_s
136
136
  else
137
- require 'unicode'
138
- Unicode.normalize_C(text)
137
+ begin
138
+ require 'unicode'
139
+ Unicode.normalize_C(text)
140
+ rescue LoadError
141
+ Blacklight.logger.warn "Unable to load unicode library in #export_as_refworks_marc_txt; skipping unicode normalization"
142
+ text
143
+ end
139
144
  end
140
145
  end
141
146