commonwealth-vlr-engine 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/app/assets/images/commonwealth-vlr-engine/vlr_mobile-icons_120x120.png +0 -0
  4. data/app/assets/images/commonwealth-vlr-engine/vlr_mobile-icons_152x152.png +0 -0
  5. data/app/assets/images/commonwealth-vlr-engine/vlr_mobile-icons_60x60.png +0 -0
  6. data/app/assets/images/commonwealth-vlr-engine/vlr_mobile-icons_76x76.png +0 -0
  7. data/app/assets/javascripts/blacklight_google_analytics/blacklight_google_analytics.js.erb +11 -0
  8. data/app/assets/javascripts/commonwealth-vlr-engine.js +3 -0
  9. data/app/assets/javascripts/commonwealth-vlr-engine/download_utils.js +4 -0
  10. data/app/assets/stylesheets/commonwealth-vlr-engine/commonwealth-vlr-engine.css +1 -0
  11. data/app/assets/stylesheets/commonwealth-vlr-engine/downloads.scss +18 -0
  12. data/app/assets/stylesheets/commonwealth-vlr-engine/facets.scss +64 -0
  13. data/app/assets/stylesheets/commonwealth-vlr-engine/vlr_dependencies.css +3 -1
  14. data/app/controllers/bookmarks_controller.rb +7 -2
  15. data/app/controllers/collections_controller.rb +1 -109
  16. data/app/controllers/concerns/commonwealth_vlr_engine/collections_controller_behavior.rb +132 -0
  17. data/app/controllers/concerns/commonwealth_vlr_engine/downloads_controller_behavior.rb +184 -0
  18. data/app/controllers/concerns/commonwealth_vlr_engine/institutions_controller_behavior.rb +70 -0
  19. data/app/controllers/downloads_controller.rb +4 -0
  20. data/app/controllers/iiif_manifest_controller.rb +2 -7
  21. data/app/controllers/image_viewer_controller.rb +3 -13
  22. data/app/controllers/institutions_controller.rb +1 -65
  23. data/app/controllers/ocr_search_controller.rb +1 -1
  24. data/app/controllers/saved_searches_controller.rb +2 -0
  25. data/app/controllers/search_history_controller.rb +2 -0
  26. data/app/helpers/commonwealth_vlr_engine/application_helper.rb +20 -2
  27. data/app/helpers/commonwealth_vlr_engine/catalog_helper.rb +36 -53
  28. data/app/helpers/commonwealth_vlr_engine/downloads_helper_behavior.rb +192 -0
  29. data/app/helpers/commonwealth_vlr_engine/facets_helper.rb +3 -1
  30. data/app/helpers/commonwealth_vlr_engine/ocr_search_helper_behavior.rb +5 -0
  31. data/app/helpers/commonwealth_vlr_engine/search_history_constraints_helper.rb +25 -0
  32. data/app/helpers/downloads_helper.rb +3 -0
  33. data/app/views/catalog/_add_this.html.erb +3 -1
  34. data/app/views/catalog/_folder_item_control.html.erb +2 -1
  35. data/app/views/catalog/_index_mapview.html.erb +9 -0
  36. data/app/views/catalog/_more_like_this.html.erb +1 -1
  37. data/app/views/catalog/_show_cite_tools.html.erb +3 -0
  38. data/app/views/catalog/_show_default.html.erb +13 -12
  39. data/app/views/catalog/_show_partials/_show_book_viewer_link.html.erb +1 -1
  40. data/app/views/catalog/_show_partials/_show_default_metadata.html.erb +3 -3
  41. data/app/views/catalog/_show_partials/_show_downloads.html.erb +1 -1
  42. data/app/views/catalog/_show_partials/_show_volumes.html.erb +1 -1
  43. data/app/views/catalog/_show_sharing_tools.html.erb +3 -0
  44. data/app/views/collections/show.html.erb +1 -0
  45. data/app/views/downloads/_terms_of_use.html.erb +29 -0
  46. data/app/views/downloads/show.html.erb +29 -0
  47. data/app/views/image_viewer/_render_book_viewer.html.erb +1 -1
  48. data/app/views/institutions/show.html.erb +2 -10
  49. data/app/views/layouts/commonwealth-vlr-engine.html.erb +1 -4
  50. data/app/views/ocr_search/_index_ocr_list.html.erb +3 -3
  51. data/app/views/shared/_mobile_icon_tags.html.erb +4 -0
  52. data/app/views/shared/_search_form_header.html.erb +1 -1
  53. data/app/views/shared/_tools.html.erb +5 -5
  54. data/commonwealth-vlr-engine.gemspec +8 -6
  55. data/config/initializers/patch_blacklight_advanced_search.rb +6 -6
  56. data/config/initializers/patch_blacklight_range_limit.rb +18 -0
  57. data/config/jetty.yml +1 -1
  58. data/config/locales/commonwealth-vlr-engine.en.yml +12 -0
  59. data/config/routes.rb +6 -0
  60. data/lib/commonwealth-vlr-engine.rb +1 -0
  61. data/lib/commonwealth-vlr-engine/controller.rb +18 -3
  62. data/lib/commonwealth-vlr-engine/controller_override.rb +79 -21
  63. data/lib/commonwealth-vlr-engine/engine.rb +1 -0
  64. data/lib/commonwealth-vlr-engine/render_constraints_override.rb +15 -14
  65. data/lib/commonwealth-vlr-engine/search_builder/collections_search_builder.rb +1 -1
  66. data/lib/commonwealth-vlr-engine/search_builder/commonwealth_search_builder_behavior.rb +13 -1
  67. data/lib/commonwealth-vlr-engine/search_builder/flagged_search_builder.rb +1 -1
  68. data/lib/commonwealth-vlr-engine/search_builder/institutions_search_builder.rb +1 -1
  69. data/lib/commonwealth-vlr-engine/search_builder/mlt_search_builder.rb +2 -1
  70. data/lib/commonwealth-vlr-engine/streaming.rb +50 -0
  71. data/lib/commonwealth-vlr-engine/version.rb +1 -1
  72. data/lib/generators/commonwealth_vlr_engine/routes_generator.rb +8 -0
  73. data/lib/generators/commonwealth_vlr_engine/templates/commonwealth_search_builder.rb +4 -3
  74. data/lib/generators/commonwealth_vlr_engine/templates/config/vlr.yml +3 -0
  75. data/solr_conf/conf/solrconfig.xml +42 -5
  76. data/spec/controllers/collections_controller_spec.rb +20 -0
  77. data/spec/controllers/downloads_controller_spec.rb +65 -0
  78. data/spec/controllers/image_viewer_controller_spec.rb +0 -18
  79. data/spec/controllers/institutions_controller_spec.rb +7 -0
  80. data/spec/features/advanced_search_date_range_spec.rb +36 -0
  81. data/spec/features/collections/index_spec.rb +6 -0
  82. data/spec/features/collections/show_spec.rb +38 -0
  83. data/spec/features/more_like_this_search_spec.rb +18 -1
  84. data/spec/fixtures/sample_solr_documents.yml +107 -19
  85. data/spec/helpers/application_helper_spec.rb +9 -2
  86. data/spec/helpers/catalog_helper_spec.rb +26 -42
  87. data/spec/helpers/downloads_helper_spec.rb +173 -0
  88. data/spec/helpers/ocr_search_helper_spec.rb +15 -7
  89. data/spec/helpers/range_limit_helper_spec.rb +20 -0
  90. data/spec/helpers/search_history_constraints_helper_spec.rb +39 -0
  91. data/spec/lib/commonwealth-vlr-engine/controller_override_spec.rb +37 -0
  92. data/spec/lib/commonwealth-vlr-engine/render_constraints_override_spec.rb +0 -10
  93. data/spec/lib/commonwealth-vlr-engine/search_builder/commonwealth_search_builder_behavior_spec.rb +21 -3
  94. data/spec/lib/commonwealth-vlr-engine/search_builder/mlt_search_builder_spec.rb +1 -1
  95. metadata +99 -12
  96. data/app/helpers/commonwealth_vlr_engine/component_helper.rb +0 -22
  97. data/app/views/catalog/_show_tools.html.erb +0 -42
  98. data/spec/helpers/component_helper_spec.rb +0 -34
@@ -0,0 +1,18 @@
1
+ # need to override RangeLimitHelper#add_range_missing, this seems to be only way that works
2
+
3
+ RangeLimitHelper.module_eval do
4
+
5
+ def add_range_missing(solr_field, my_params = params)
6
+ my_params = Marshal.load(Marshal.dump(my_params))
7
+ my_params["range"] ||= {}
8
+ my_params["range"][solr_field] ||= {}
9
+ my_params["range"][solr_field]["missing"] = "true"
10
+
11
+ # Need to ensure there's a search_field to trick Blacklight
12
+ # into displaying results, not placeholder page. Kind of hacky,
13
+ # but works for now.
14
+ my_params["search_field"] ||= "dummy_range"
15
+ search_catalog_path(my_params.except('controller', 'action'))
16
+ end
17
+
18
+ end
@@ -3,5 +3,5 @@ development:
3
3
  jetty_port: 8983
4
4
  test:
5
5
  startup_wait: 60
6
- jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
6
+ jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8983 %>
7
7
  <%= ENV['TEST_JETTY_PATH'] ? "jetty_home: " + ENV['TEST_JETTY_PATH'] : '' %>
@@ -6,6 +6,8 @@ en:
6
6
  page_title: 'Search'
7
7
  title: 'Search - %{application_name}'
8
8
  limit: 'Narrow your search:'
9
+ constraints:
10
+ date: 'Date Range'
9
11
 
10
12
  application_name: 'SITE_NAME'
11
13
  application_desc: 'SITE DESCRIPTION'
@@ -79,8 +81,15 @@ en:
79
81
  did_you_mean: 'Search for %{options} instead?'
80
82
 
81
83
  downloads:
84
+ cc: 'Learn more about this Creative Commons license'
82
85
  link_info: '(links open in new window)'
83
86
  title: 'Downloads'
87
+ images:
88
+ access800: 'Medium (800px)'
89
+ accessFull: 'Original (full resolution)'
90
+ georectifiedMaster: 'GeoTIFF (georeferenced)'
91
+ JPEG2000: 'Original (full resolution)'
92
+ productionMaster: 'Master (full resolution, uncompressed)'
84
93
 
85
94
  email:
86
95
  form:
@@ -343,6 +352,9 @@ en:
343
352
  explore:
344
353
  title: 'Explore'
345
354
 
355
+ range_limit:
356
+ submit_limit: 'Apply'
357
+
346
358
  saved_searches:
347
359
  clear:
348
360
  action_title: 'clear all'
@@ -13,10 +13,12 @@ Rails.application.routes.draw do
13
13
  get 'search/:id/metadata_view', :to => 'catalog#metadata_view', :as => 'metadata_view_catalog'
14
14
 
15
15
  # collections
16
+ get 'collections/range_limit', to: 'collections#range_limit'
16
17
  resources :collections, :only => [:index, :show]
17
18
  get 'collections/facet/:id', :to => 'collections#facet', :as => 'collections_facet'
18
19
 
19
20
  # institutions
21
+ get 'institutions/range_limit', to: 'institutions#range_limit'
20
22
  resources :institutions, :only => [:index, :show]
21
23
  get 'institutions/facet/:id', :to => 'institutions#facet', :as => 'institutions_facet'
22
24
 
@@ -55,6 +57,10 @@ Rails.application.routes.draw do
55
57
  # OCR search results
56
58
  get 'search/:id/fulltext', :to => 'ocr_search#index', :as => 'ocr_search'
57
59
 
60
+ # downloads
61
+ resources :downloads, :only => [:show]
62
+ get 'start_download/:id', :to => 'downloads#trigger_download', :as => 'trigger_downloads'
63
+
58
64
  # DEPRECATED ROUTES AND EXAMPLES
59
65
 
60
66
  # this is generated into local app via CommonwealthVlrEngine::RoutesGenerator
@@ -16,6 +16,7 @@ module CommonwealthVlrEngine
16
16
  require 'commonwealth-vlr-engine/finder'
17
17
  require 'commonwealth-vlr-engine/notifier'
18
18
  require 'commonwealth-vlr-engine/iiif_manifest'
19
+ require 'commonwealth-vlr-engine/streaming'
19
20
 
20
21
  def self.config
21
22
  @config ||= YAML::load(File.open(config_path))[env]
@@ -47,8 +47,13 @@ module CommonwealthVlrEngine
47
47
  page_sequence
48
48
  end
49
49
 
50
+ def not_found
51
+ raise ActionController::RoutingError.new('Not Found')
52
+ end
53
+
50
54
  # override of Blacklight::Controller#search_action_path
51
- # for proper constraints linking in collections#index and institutions#index
55
+ # for proper constraints and facet links in collections and institution views
56
+ # gets a bit tricky for collections#facet, since this has multiple contexts (collections#index and collections#show)
52
57
  def search_action_path *args
53
58
  if args.first.is_a? Hash
54
59
  args.first[:only_path] = true
@@ -58,8 +63,18 @@ module CommonwealthVlrEngine
58
63
 
59
64
  if params[:controller] == 'institutions' && params[:action] == 'index'
60
65
  institutions_url *args
61
- elsif params[:controller] == 'collections' && (params[:action] == 'index' || params[:action] == 'facet')
62
- collections_url *args
66
+ elsif params[:controller] == 'collections'
67
+ if params[:action] == 'index'
68
+ collections_url *args
69
+ elsif params[:action] == 'facet'
70
+ if request.query_parameters['f'] && request.query_parameters['f'][blacklight_config.collection_field]
71
+ search_action_url *args
72
+ else
73
+ collections_url *args
74
+ end
75
+ else
76
+ search_action_url *args
77
+ end
63
78
  else
64
79
  search_action_url *args
65
80
  end
@@ -14,7 +14,12 @@ module CommonwealthVlrEngine
14
14
  # add BlacklightMaps
15
15
  self.send(:include, BlacklightMaps::ControllerOverride)
16
16
 
17
+ # add BlacklightRangeLimit
18
+ self.send(:include, BlacklightRangeLimit::ControllerOverride)
19
+
20
+ # HEADS UP: these filters get inherited by any subclass of CatalogController
17
21
  before_filter :get_object_files, :only => [:show]
22
+ before_filter :mlt_results_for_show, :only => [:show]
18
23
  before_filter :set_nav_context, :only => [:index]
19
24
  before_filter :mlt_search, :only => [:index]
20
25
  before_filter :add_institution_fields, :only => [:index, :facet]
@@ -38,8 +43,8 @@ module CommonwealthVlrEngine
38
43
  config.view.maps.geojson_field = 'subject_geojson_facet_ssim'
39
44
  config.view.maps.coordinates_field = 'subject_coordinates_geospatial'
40
45
  config.view.maps.placename_field = 'subject_geographic_ssim'
41
- config.view.maps.maxzoom = 13
42
- config.view.maps.show_initial_zoom = 9
46
+ config.view.maps.maxzoom = 14
47
+ config.view.maps.show_initial_zoom = 12
43
48
  config.view.maps.facet_mode = 'geojson'
44
49
 
45
50
  # helper that returns thumbnail URLs
@@ -47,8 +52,6 @@ module CommonwealthVlrEngine
47
52
 
48
53
  # configuration for search results/index views
49
54
  config.index.partials = [:thumbnail, :index_header, :index]
50
- #config.index.document_actions
51
- config.index.document_actions.delete(:bookmark) # don't show bookmark control
52
55
 
53
56
  # solr field configuration for document/show views
54
57
  config.show.title_field = 'title_info_primary_tsi'
@@ -61,7 +64,7 @@ module CommonwealthVlrEngine
61
64
  config.advanced_search = {
62
65
  qt: 'search',
63
66
  url_key: 'advanced',
64
- query_parser: 'dismax',
67
+ query_parser: 'edismax',
65
68
  form_solr_parameters: {
66
69
  'facet.field' => ['genre_basic_ssim', 'collection_name_ssim'],
67
70
  'facet.limit' => -1, # return all facet values
@@ -87,7 +90,7 @@ module CommonwealthVlrEngine
87
90
  # solr fields that will be treated as facets by the blacklight application
88
91
  config.add_facet_field 'subject_facet_ssim', label: 'Topic', limit: 8, sort: 'count', collapse: false
89
92
  config.add_facet_field 'subject_geographic_ssim', label: 'Place', limit: 8, sort: 'count', collapse: false
90
- config.add_facet_field 'date_facet_ssim', label: 'Date', limit: 8, sort: 'index', collapse: false
93
+ config.add_facet_field 'date_facet_yearly_ssim', :label => 'Date', :range => true, :collapse => false
91
94
  config.add_facet_field 'genre_basic_ssim', label: 'Format', limit: 8, sort: 'count', helper_method: :render_format, collapse: false
92
95
  config.add_facet_field 'collection_name_ssim', label: 'Collection', limit: 8, sort: 'count', collapse: false
93
96
  # link_to_facet fields (not in facets sidebar of search results)
@@ -98,6 +101,7 @@ module CommonwealthVlrEngine
98
101
  config.add_facet_field 'related_item_subsubseries_ssim', label: 'Sub-subseries', include_in_request: false
99
102
  config.add_facet_field 'institution_name_ssim', label: 'Institution', include_in_request: false
100
103
  config.add_facet_field 'name_facet_ssim', label: 'Name', include_in_request: false
104
+ config.add_facet_field 'title_info_uniform_ssim', label: 'Title (uniform)', include_in_request: false
101
105
  # facet for blacklight-maps catalog#index map view
102
106
  # have to use '-2' to get all values
103
107
  # because Blacklight::RequestBuilders#solr_facet_params adds '+1' to value
@@ -153,6 +157,24 @@ module CommonwealthVlrEngine
153
157
  config.add_sort_field 'date_start_dtsi asc, title_info_primary_ssort asc', label: 'date (asc)'
154
158
  config.add_sort_field 'date_start_dtsi desc, title_info_primary_ssort asc', label: 'date (desc)'
155
159
 
160
+ # remove BL default show tools
161
+ config.show.document_actions.delete(:email)
162
+ config.show.document_actions.delete(:sms)
163
+ config.show.document_actions.delete(:bookmark)
164
+ config.show.document_actions.delete(:citation)
165
+
166
+ # index actions to remove
167
+ config.index.document_actions.delete(:bookmark)
168
+
169
+ # add our custom tools
170
+ config.add_show_tools_partial :add_this, partial: 'add_this'
171
+ config.add_show_tools_partial :folder_items, partial: 'folder_item_control'
172
+ config.add_show_tools_partial :custom_email, partial: 'show_sharing_tools'
173
+ config.add_show_tools_partial :cite, partial: 'show_cite_tools'
174
+
175
+ # add 'more like this' params in catalog#show
176
+ #config.default_document_solr_params = mlt_params_for_show
177
+
156
178
  end
157
179
 
158
180
  # displays the MODS XML record. copied from blacklight-marc 'librarian_view'
@@ -166,7 +188,7 @@ module CommonwealthVlrEngine
166
188
  end
167
189
  end
168
190
 
169
- # modify facet settings for Collections#show and Institutions#show
191
+ # modify BL config settings for Collections#show and Institutions#show
170
192
  def relation_base_blacklight_config
171
193
  # don't show collection facet
172
194
  blacklight_config.facet_fields['collection_name_ssim'].show = false
@@ -174,8 +196,13 @@ module CommonwealthVlrEngine
174
196
  # collapse remaining facets
175
197
  blacklight_config.facet_fields['subject_facet_ssim'].collapse = true
176
198
  blacklight_config.facet_fields['subject_geographic_ssim'].collapse = true
177
- blacklight_config.facet_fields['date_facet_ssim'].collapse = true
199
+ blacklight_config.facet_fields['date_facet_yearly_ssim'].collapse = true
178
200
  blacklight_config.facet_fields['genre_basic_ssim'].collapse = true
201
+ # remove item-centric show tools (for admin)
202
+ blacklight_config.show.document_actions.delete(:add_this)
203
+ blacklight_config.show.document_actions.delete(:folder_items)
204
+ blacklight_config.show.document_actions.delete(:custom_email)
205
+ blacklight_config.show.document_actions.delete(:cite)
179
206
  end
180
207
 
181
208
  end
@@ -194,20 +221,53 @@ module CommonwealthVlrEngine
194
221
  render :facet
195
222
  end
196
223
 
224
+ # TODO: refactor how views access files/volumes/etc.
225
+ # returns the child volumes for Book objects (if they exist)
226
+ # needs to be in this module because CommonwealthVlrEngine::Finder methods aren't accessible in helpers/views
227
+ def has_volumes?(document)
228
+ case document[blacklight_config.show.display_type_field.to_sym]
229
+ when 'Book'
230
+ volumes = get_volume_objects(document.id)
231
+ else
232
+ volumes = nil
233
+ end
234
+ volumes.presence
235
+ end
236
+
237
+ private
238
+
239
+ # LOCAL OVERRIDE of Blacklight::SearchHelper
240
+ # needed so that Solr query for prev/next/total in catalog#show view uses correct SearchBuilder class
241
+ # because params added exclusively in SearchBuilder methods don't get saved by current_search_session
242
+ def get_previous_and_next_documents_for_search(index, request_params, extra_controller_params={})
243
+ search_builder_to_use = request_params[:mlt_id] ? CommonwealthMltSearchBuilder.new(self) : search_builder
244
+ p = previous_and_next_document_params(index)
245
+ query = search_builder_to_use.with(request_params).start(p.delete(:start)).rows(p.delete(:rows)).merge(extra_controller_params).merge(p)
246
+ response = repository.search(query)
247
+ document_list = response.documents
248
+
249
+ # only get the previous doc if there is one
250
+ prev_doc = document_list.first if index > 0
251
+ next_doc = document_list.last if (index + 1) < response.total
252
+ [response, [prev_doc, next_doc]]
253
+ end
254
+
197
255
  # if this is 'more like this' search, solr id = params[:mlt_id]
198
256
  def mlt_search
199
- if params[:mlt_id]
257
+ if controller_name == 'catalog' && params[:mlt_id]
200
258
  blacklight_config.search_builder_class = CommonwealthMltSearchBuilder
201
259
  end
202
260
  end
203
261
 
204
262
  # TODO: refactor how views access files/volumes/etc.
205
263
  def get_object_files
206
- @object_files = get_files(params[:id])
264
+ if controller_name == 'catalog' || controller_name == 'image_viewer'
265
+ @object_files = get_files(params[:id])
266
+ end
207
267
  end
208
268
 
209
269
  def set_nav_context
210
- @nav_li_active = 'search'
270
+ @nav_li_active = 'search' if controller_name == 'catalog'
211
271
  end
212
272
 
213
273
  # add institutions if configured
@@ -218,17 +278,15 @@ module CommonwealthVlrEngine
218
278
  end
219
279
  end
220
280
 
221
- # TODO: refactor how views access files/volumes/etc.
222
- # returns the child volumes for Book objects (if they exist)
223
- # needs to be in this module because CommonwealthVlrEngine::Finder methods aren't accessible in helpers/views
224
- def has_volumes?(document)
225
- case document[blacklight_config.show.display_type_field.to_sym]
226
- when 'Book'
227
- volumes = get_volume_objects(document.id)
228
- else
229
- volumes = nil
281
+ # run a separate search for 'more like this' items
282
+ # so we can explicitly set params to exclude unwanted items
283
+ def mlt_results_for_show
284
+ if controller_name == 'catalog'
285
+ blacklight_config.search_builder_class = CommonwealthMltSearchBuilder
286
+ (@mlt_response, @mlt_document_list) = search_results(mlt_id: params[:id], rows: 4)
287
+ # have to reset to CommonwealthSearchBuilder, or prev/next links won't work
288
+ blacklight_config.search_builder_class = CommonwealthSearchBuilder
230
289
  end
231
- volumes.presence
232
290
  end
233
291
 
234
292
  protected
@@ -2,6 +2,7 @@ require 'blacklight'
2
2
  require 'blacklight/gallery'
3
3
  require 'blacklight_advanced_search'
4
4
  require 'blacklight/maps'
5
+ require 'blacklight_range_limit'
5
6
  require 'bpluser'
6
7
  require 'typhoeus'
7
8
  require 'devise'
@@ -24,9 +24,22 @@ module CommonwealthVlrEngine
24
24
  super
25
25
  end
26
26
 
27
- # override to add method to show constraint for 'more like this' search
27
+ # override to add methods to show constraints for 'more like this' and advanced search date range
28
28
  def render_constraints(localized_params = params)
29
- render_mlt_query(localized_params) + super
29
+ render_mlt_query(localized_params) + render_advanced_date_query(localized_params) + super
30
+ end
31
+
32
+ # Render the advanced search date query constraints
33
+ def render_advanced_date_query(localized_params = params)
34
+ # So simple don't need a view template, we can just do it here.
35
+ return ''.html_safe if localized_params[:date_start].blank? && localized_params[:date_end].blank?
36
+
37
+ render_constraint_element(t('blacklight.advanced_search.constraints.date'),
38
+ date_range_constraints_to_s(localized_params),
39
+ :classes => ['date_range'],
40
+ :remove => remove_constraint_url(localized_params.merge(date_start: nil,
41
+ date_end: nil,
42
+ :action=>'index')))
30
43
  end
31
44
 
32
45
  # Render the 'more like this' query constraints
@@ -42,17 +55,5 @@ module CommonwealthVlrEngine
42
55
  :action=>'index')))
43
56
  end
44
57
 
45
- # include render_search_to_s_mlt() in rendered constraints
46
- # Simpler textual version of constraints, used on Search History page.
47
- def render_search_to_s(params)
48
- render_search_to_s_mlt(params) + super
49
- end
50
-
51
- # render the MLT search query constraint, used on Search History page.
52
- def render_search_to_s_mlt(params)
53
- return "".html_safe if params[:mlt_id].blank?
54
- render_search_to_s_element(t('blacklight.more_like_this.constraint_label'), render_filter_value(params[:mlt_id]) )
55
- end
56
-
57
58
  end
58
59
  end
@@ -4,7 +4,7 @@ class CommonwealthCollectionsSearchBuilder < Blacklight::SearchBuilder
4
4
  include CommonwealthVlrEngine::CommonwealthSearchBuilderBehavior
5
5
 
6
6
  self.default_processor_chain += [
7
- :exclude_unpublished_items, :collections_filter
7
+ :site_filter, :exclude_unpublished_items, :collections_filter
8
8
  ]
9
9
 
10
10
  unless I18n.t('blacklight.home.browse.institutions.enabled')
@@ -1,6 +1,12 @@
1
1
  module CommonwealthVlrEngine
2
2
  module CommonwealthSearchBuilderBehavior
3
3
 
4
+ # only return items corresponding to the correct site
5
+ def site_filter(solr_parameters = {})
6
+ solr_parameters[:fq] ||= []
7
+ solr_parameters[:fq] << '+destination_site_ssim:"' + CommonwealthVlrEngine.config[:site] + '"'
8
+ end
9
+
4
10
  # keep file assets from appearing in search results
5
11
  def exclude_unwanted_models(solr_parameters = {})
6
12
  solr_parameters[:fq] ||= []
@@ -44,8 +50,14 @@ module CommonwealthVlrEngine
44
50
  end
45
51
 
46
52
  # for 'more like this' search -- set solr id param to params[:mlt_id]
47
- def set_solr_id_for_mlt(solr_parameters = {})
53
+ def mlt_params(solr_parameters = {})
48
54
  solr_parameters[:id] = blacklight_params[:mlt_id]
55
+ solr_parameters[:qt] = 'mlt'
56
+ solr_parameters[:mlt] = true
57
+ solr_parameters[:'mlt.fl'] = 'subject_facet_ssim,subject_geo_city_ssim,related_item_host_ssim'
58
+ solr_parameters[:'mlt.match.include'] = false
59
+ solr_parameters[:'mlt.mintf'] = 1
60
+ solr_parameters[:'mlt.qf'] = 'subject_facet_ssim^10 subject_geo_city_ssim^5 related_item_host_ssim'
49
61
  end
50
62
 
51
63
  # used by CollectionsController#index
@@ -4,7 +4,7 @@ class CommonwealthFlaggedSearchBuilder < Blacklight::SearchBuilder
4
4
  include CommonwealthVlrEngine::CommonwealthSearchBuilderBehavior
5
5
 
6
6
  self.default_processor_chain += [
7
- :exclude_unpublished_items, :flagged_filter
7
+ :site_filter, :exclude_unpublished_items, :flagged_filter
8
8
  ]
9
9
 
10
10
  unless I18n.t('blacklight.home.browse.institutions.enabled')
@@ -5,7 +5,7 @@ class CommonwealthInstitutionsSearchBuilder < Blacklight::SearchBuilder
5
5
  include CommonwealthVlrEngine::CommonwealthSearchBuilderBehavior
6
6
 
7
7
  self.default_processor_chain += [
8
- :exclude_unpublished_items, :institutions_filter
8
+ :site_filter, :exclude_unpublished_items, :institutions_filter
9
9
  ]
10
10
 
11
11
  end
@@ -2,10 +2,11 @@ class CommonwealthMltSearchBuilder < Blacklight::SearchBuilder
2
2
 
3
3
  include Blacklight::Solr::SearchBuilderBehavior
4
4
  include BlacklightMaps::MapsSearchBuilderBehavior
5
+ include BlacklightRangeLimit::RangeLimitBuilder
5
6
  include CommonwealthVlrEngine::CommonwealthSearchBuilderBehavior
6
7
 
7
8
  self.default_processor_chain += [
8
- :set_solr_id_for_mlt, :exclude_unpublished_items, :exclude_volumes
9
+ :site_filter, :mlt_params, :exclude_unpublished_items, :exclude_volumes
9
10
  ]
10
11
 
11
12
  unless I18n.t('blacklight.home.browse.institutions.enabled')
@@ -0,0 +1,50 @@
1
+ # this is heavily based on ActiveFedora::File::Streaming
2
+ module CommonwealthVlrEngine
3
+ module Streaming
4
+ extend ActiveSupport::Concern
5
+
6
+ # @param range [String] the Range HTTP header
7
+ # @return [Stream] an object that responds to each
8
+ def file_stream(uri, range = nil)
9
+ uri = URI.parse(uri)
10
+ FileBody.new(uri, stream_headers(range))
11
+ end
12
+
13
+ # @param range [String] from #stream
14
+ # @return [Hash]
15
+ def stream_headers(range, result = {})
16
+ result["Range"] = range if range
17
+ result
18
+ end
19
+
20
+ class FileBody
21
+ attr_reader :uri, :headers
22
+ def initialize(uri, headers)
23
+ @uri = uri
24
+ @headers = headers
25
+ end
26
+
27
+ def each(no_of_requests_limit = 3, &block)
28
+ raise ArgumentError, 'HTTP redirect too deep' if no_of_requests_limit.zero?
29
+ Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
30
+ request = Net::HTTP::Get.new uri, headers
31
+ http.request request do |response|
32
+ case response
33
+ when Net::HTTPSuccess
34
+ response.read_body do |chunk|
35
+ yield chunk
36
+ end
37
+ when Net::HTTPRedirection
38
+ no_of_requests_limit -= 1
39
+ @uri = URI(response["location"])
40
+ each(no_of_requests_limit, &block)
41
+ else
42
+ raise "Couldn't get data from Fedora (#{uri}). Response: #{response.code}"
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+ end