blacklight 5.9.4 → 5.10.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/Gemfile +1 -1
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_facets.scss +11 -10
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +14 -14
- data/app/helpers/blacklight/configuration_helper_behavior.rb +16 -10
- data/app/helpers/blacklight/facets_helper_behavior.rb +15 -14
- data/app/helpers/blacklight/url_helper_behavior.rb +1 -1
- data/app/models/bookmark.rb +1 -4
- data/app/models/search.rb +3 -6
- data/app/views/catalog/_facet_layout.html.erb +2 -2
- data/app/views/catalog/_facet_limit.html.erb +5 -3
- data/app/views/catalog/_facet_pivot.html.erb +4 -4
- data/app/views/catalog/_home_text.html.erb +8 -48
- data/app/views/catalog/_index_default.html.erb +3 -3
- data/app/views/catalog/_show_default.html.erb +3 -3
- data/app/views/catalog/_sms_form.html.erb +1 -1
- data/app/views/catalog/facet.html.erb +1 -1
- data/blacklight.gemspec +1 -1
- data/config/jetty.yml +0 -3
- data/config/locales/blacklight.de.yml +2 -0
- data/config/locales/blacklight.en.yml +2 -0
- data/config/locales/blacklight.es.yml +2 -0
- data/config/locales/blacklight.fr.yml +2 -0
- data/config/locales/blacklight.pt-BR.yml +2 -0
- data/lib/blacklight.rb +70 -26
- data/lib/blacklight/abstract_repository.rb +29 -0
- data/lib/blacklight/base.rb +7 -7
- data/lib/blacklight/bookmarks.rb +5 -5
- data/lib/blacklight/catalog.rb +34 -19
- data/lib/blacklight/catalog/search_context.rb +1 -1
- data/lib/blacklight/configuration.rb +112 -46
- data/lib/blacklight/configuration/facet_field.rb +9 -7
- data/lib/blacklight/configuration/field.rb +27 -0
- data/lib/blacklight/configuration/fields.rb +25 -20
- data/lib/blacklight/configuration/search_field.rb +6 -8
- data/lib/blacklight/configuration/solr_field.rb +3 -18
- data/lib/blacklight/configuration/sort_field.rb +6 -7
- data/lib/blacklight/document.rb +156 -0
- data/lib/blacklight/document/dublin_core.rb +41 -0
- data/lib/blacklight/document/email.rb +16 -0
- data/lib/blacklight/document/export.rb +107 -0
- data/lib/blacklight/document/extensions.rb +56 -0
- data/lib/blacklight/document/schema_org.rb +7 -0
- data/lib/blacklight/document/semantic_fields.rb +51 -0
- data/lib/blacklight/document/sms.rb +14 -0
- data/lib/blacklight/document_presenter.rb +3 -3
- data/lib/blacklight/exceptions.rb +9 -2
- data/lib/blacklight/facet.rb +21 -16
- data/lib/blacklight/request_builders.rb +60 -284
- data/lib/blacklight/routes.rb +1 -1
- data/lib/blacklight/search_builder.rb +130 -0
- data/lib/blacklight/search_helper.rb +316 -0
- data/lib/blacklight/solr.rb +1 -0
- data/lib/blacklight/solr/document.rb +4 -187
- data/lib/blacklight/solr/document/dublin_core.rb +3 -37
- data/lib/blacklight/solr/document/email.rb +4 -13
- data/lib/blacklight/solr/document/export.rb +3 -103
- data/lib/blacklight/solr/document/extensions.rb +4 -52
- data/lib/blacklight/solr/document/more_like_this.rb +1 -1
- data/lib/blacklight/solr/document/schema_org.rb +4 -4
- data/lib/blacklight/solr/document/sms.rb +4 -11
- data/lib/blacklight/solr/facet_paginator.rb +2 -2
- data/lib/blacklight/solr/search_builder.rb +264 -0
- data/lib/blacklight/solr_helper.rb +6 -261
- data/lib/blacklight/solr_repository.rb +30 -24
- data/lib/blacklight/solr_response.rb +3 -3
- data/lib/blacklight/user.rb +1 -2
- data/lib/blacklight/utils.rb +0 -23
- data/lib/generators/blacklight/controller_generator.rb +38 -0
- data/lib/generators/blacklight/document_generator.rb +20 -0
- data/lib/generators/blacklight/install_generator.rb +38 -39
- data/lib/generators/blacklight/models_generator.rb +2 -62
- data/lib/generators/blacklight/templates/catalog_controller.rb +3 -4
- data/lib/generators/blacklight/templates/config/{solr.yml → blacklight.yml} +3 -0
- data/lib/generators/blacklight/templates/config/jetty.yml +0 -3
- data/lib/generators/blacklight/templates/solr_document.rb +6 -6
- data/lib/generators/blacklight/test_support_generator.rb +1 -6
- data/lib/generators/blacklight/user_generator.rb +59 -0
- data/lib/railties/blacklight.rake +16 -7
- data/spec/controllers/catalog_controller_spec.rb +9 -15
- data/spec/features/facets_spec.rb +8 -0
- data/spec/helpers/configuration_helper_spec.rb +6 -13
- data/spec/helpers/facets_helper_spec.rb +3 -2
- data/spec/lib/blacklight/configuration_spec.rb +11 -38
- data/spec/lib/blacklight/{solr/document → document}/dublin_core_spec.rb +4 -4
- data/spec/lib/blacklight/{solr/document → document}/email_spec.rb +2 -2
- data/spec/lib/blacklight/{solr/document → document}/sms_spec.rb +2 -2
- data/spec/lib/blacklight/search_builder_spec.rb +145 -0
- data/spec/lib/blacklight/search_helper_spec.rb +775 -0
- data/spec/lib/blacklight/solr/document/more_like_this_spec.rb +1 -1
- data/spec/lib/blacklight/solr/search_builder_spec.rb +561 -0
- data/spec/lib/blacklight/solr_helper_spec.rb +5 -1291
- data/spec/lib/blacklight/solr_repository_spec.rb +13 -13
- data/spec/models/record_mailer_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- data/spec/views/catalog/_constraints.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +2 -2
- data/spec/views/catalog/index.atom.builder_spec.rb +1 -1
- data/tasks/blacklight.rake +1 -1
- data/template.demo.rb +1 -1
- metadata +33 -45
- data/doc/Adding-new-document-actions.md +0 -94
- data/doc/Atom-Responses.md +0 -90
- data/doc/Blacklight-Add-ons.md +0 -23
- data/doc/Blacklight-configuration.md +0 -411
- data/doc/Blacklight-on-Heroku.md +0 -100
- data/doc/Blacklight-out-of-the-box.md +0 -47
- data/doc/Bookmarks.md +0 -1
- data/doc/Code4Lib-2014.md +0 -94
- data/doc/Configuration---Facet-Fields.md +0 -130
- data/doc/Configuration---Results-View.md +0 -224
- data/doc/Configuration---Solr-fields.md +0 -106
- data/doc/Configuring-and-Customizing-Blacklight.md +0 -257
- data/doc/Configuring-rails-routes.md +0 -13
- data/doc/Contributing-to-Blacklight.md +0 -43
- data/doc/Examples.md +0 -120
- data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -141
- data/doc/Home.md +0 -100
- data/doc/How-to-release-a-version.md +0 -45
- data/doc/Indexing-your-data-into-solr.md +0 -36
- data/doc/Internationalization.md +0 -32
- data/doc/JSON-API.md +0 -83
- data/doc/Pagination.md +0 -52
- data/doc/Providing-your-own-view-templates.md +0 -69
- data/doc/Quickstart.md +0 -153
- data/doc/README_SOLR.md +0 -245
- data/doc/Saved-Searches.md +0 -5
- data/doc/Solr-Configuration.md +0 -154
- data/doc/Sunspot-for-indexing.md +0 -46
- data/doc/Support.md +0 -33
- data/doc/Theming.md +0 -62
- data/doc/Understanding-Rails-and-Blacklight.md +0 -75
- data/doc/User-Authentication.md +0 -60
- data/doc/_Sidebar.md +0 -9
- data/doc/testing.md +0 -58
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Blacklight::Solr::Document::SchemaOrg
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
include Blacklight::Document::SchemaOrg
|
|
3
|
+
|
|
4
|
+
def self.extended(document)
|
|
5
|
+
Deprecation.warn Blacklight::Solr::Document::SchemaOrg, "Blacklight::Solr::Document::SchemaOrg is deprecated; use Blacklight::Document::SchemaOrg instead."
|
|
5
6
|
end
|
|
6
|
-
|
|
7
7
|
end
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
|
-
# This module provides the body of an email export based on the document's semantic values
|
|
3
1
|
module Blacklight::Solr::Document::Sms
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
body = []
|
|
9
|
-
body << I18n.t('blacklight.sms.text.title', :value => semantics[:title].first) unless semantics[:title].blank?
|
|
10
|
-
body << I18n.t('blacklight.sms.text.author', :value => semantics[:author].first) unless semantics[:author].blank?
|
|
11
|
-
return body.join unless body.empty?
|
|
2
|
+
include Blacklight::Document::Sms
|
|
3
|
+
|
|
4
|
+
def self.extended(document)
|
|
5
|
+
Deprecation.warn Blacklight::Solr::Document::Sms, "Blacklight::Solr::Document::Sms is deprecated; use Blacklight::Document::Sms instead."
|
|
12
6
|
end
|
|
13
|
-
|
|
14
7
|
end
|
|
@@ -73,13 +73,13 @@ module Blacklight::Solr
|
|
|
73
73
|
def has_next?
|
|
74
74
|
!last_page?
|
|
75
75
|
end
|
|
76
|
-
deprecation_deprecate :has_next?
|
|
76
|
+
deprecation_deprecate :has_next? => "use #!last_page?"
|
|
77
77
|
|
|
78
78
|
#@deprecated
|
|
79
79
|
def has_previous?
|
|
80
80
|
!first_page?
|
|
81
81
|
end
|
|
82
|
-
deprecation_deprecate :has_next?
|
|
82
|
+
deprecation_deprecate :has_next? => "use #!first_page?"
|
|
83
83
|
|
|
84
84
|
def last_page?
|
|
85
85
|
limit.nil? || total_count <= limit
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
module Blacklight::Solr
|
|
2
|
+
class SearchBuilder < Blacklight::SearchBuilder
|
|
3
|
+
|
|
4
|
+
####
|
|
5
|
+
# Start with general defaults from BL config. Need to use custom
|
|
6
|
+
# merge to dup values, to avoid later mutating the original by mistake.
|
|
7
|
+
def default_solr_parameters(solr_parameters)
|
|
8
|
+
blacklight_config.default_solr_params.each do |key, value|
|
|
9
|
+
solr_parameters[key] = if value.respond_to? :deep_dup
|
|
10
|
+
value.deep_dup
|
|
11
|
+
elsif value.respond_to? :dup and value.duplicable?
|
|
12
|
+
value.dup
|
|
13
|
+
else
|
|
14
|
+
value
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
##
|
|
20
|
+
# Take the user-entered query, and put it in the solr params,
|
|
21
|
+
# including config's "search field" params for current search field.
|
|
22
|
+
# also include setting spellcheck.q.
|
|
23
|
+
def add_query_to_solr(solr_parameters)
|
|
24
|
+
###
|
|
25
|
+
# Merge in search field configured values, if present, over-writing general
|
|
26
|
+
# defaults
|
|
27
|
+
###
|
|
28
|
+
# legacy behavior of user param :qt is passed through, but over-ridden
|
|
29
|
+
# by actual search field config if present. We might want to remove
|
|
30
|
+
# this legacy behavior at some point. It does not seem to be currently
|
|
31
|
+
# rspec'd.
|
|
32
|
+
solr_parameters[:qt] = blacklight_params[:qt] if blacklight_params[:qt]
|
|
33
|
+
|
|
34
|
+
if search_field
|
|
35
|
+
solr_parameters[:qt] = search_field.qt
|
|
36
|
+
solr_parameters.merge!( search_field.solr_parameters) if search_field.solr_parameters
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
# Create Solr 'q' including the user-entered q, prefixed by any
|
|
41
|
+
# solr LocalParams in config, using solr LocalParams syntax.
|
|
42
|
+
# http://wiki.apache.org/solr/LocalParams
|
|
43
|
+
##
|
|
44
|
+
if (search_field && hash = search_field.solr_local_parameters)
|
|
45
|
+
local_params = hash.collect do |key, val|
|
|
46
|
+
key.to_s + "=" + solr_param_quote(val, :quote => "'")
|
|
47
|
+
end.join(" ")
|
|
48
|
+
solr_parameters[:q] = "{!#{local_params}}#{blacklight_params[:q]}"
|
|
49
|
+
|
|
50
|
+
##
|
|
51
|
+
# Set Solr spellcheck.q to be original user-entered query, without
|
|
52
|
+
# our local params, otherwise it'll try and spellcheck the local
|
|
53
|
+
# params!
|
|
54
|
+
solr_parameters["spellcheck.q"] ||= blacklight_params[:q]
|
|
55
|
+
elsif blacklight_params[:q].is_a? Hash
|
|
56
|
+
q = blacklight_params[:q]
|
|
57
|
+
solr_parameters[:q] = if q.values.any?(&:blank?)
|
|
58
|
+
# if any field parameters are empty, exclude _all_ results
|
|
59
|
+
"{!lucene}NOT *:*"
|
|
60
|
+
else
|
|
61
|
+
"{!lucene}" + q.map do |field, values|
|
|
62
|
+
"#{field}:(#{ Array(values).map { |x| solr_param_quote(x) }.join(" OR ")})"
|
|
63
|
+
end.join(" AND ")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
solr_parameters[:spellcheck] = 'false'
|
|
67
|
+
elsif blacklight_params[:q]
|
|
68
|
+
solr_parameters[:q] = blacklight_params[:q]
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
##
|
|
73
|
+
# Add any existing facet limits, stored in app-level HTTP query
|
|
74
|
+
# as :f, to solr as appropriate :fq query.
|
|
75
|
+
def add_facet_fq_to_solr(solr_parameters)
|
|
76
|
+
|
|
77
|
+
# convert a String value into an Array
|
|
78
|
+
if solr_parameters[:fq].is_a? String
|
|
79
|
+
solr_parameters[:fq] = [solr_parameters[:fq]]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# :fq, map from :f.
|
|
83
|
+
if ( blacklight_params[:f])
|
|
84
|
+
f_request_params = blacklight_params[:f]
|
|
85
|
+
|
|
86
|
+
f_request_params.each_pair do |facet_field, value_list|
|
|
87
|
+
Array(value_list).each do |value|
|
|
88
|
+
next if value.blank? # skip empty strings
|
|
89
|
+
solr_parameters.append_filter_query facet_value_to_fq_string(facet_field, value)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
##
|
|
96
|
+
# Add appropriate Solr facetting directives in, including
|
|
97
|
+
# taking account of our facet paging/'more'. This is not
|
|
98
|
+
# about solr 'fq', this is about solr facet.* params.
|
|
99
|
+
def add_facetting_to_solr(solr_parameters)
|
|
100
|
+
# While not used by BL core behavior, legacy behavior seemed to be
|
|
101
|
+
# to accept incoming params as "facet.field" or "facets", and add them
|
|
102
|
+
# on to any existing facet.field sent to Solr. Legacy behavior seemed
|
|
103
|
+
# to be accepting these incoming params as arrays (in Rails URL with []
|
|
104
|
+
# on end), or single values. At least one of these is used by
|
|
105
|
+
# Stanford for "faux hieararchial facets".
|
|
106
|
+
if blacklight_params.has_key?("facet.field") || blacklight_params.has_key?("facets")
|
|
107
|
+
solr_parameters[:"facet.field"].concat( [blacklight_params["facet.field"], blacklight_params["facets"]].flatten.compact ).uniq!
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
blacklight_config.facet_fields.select { |field_name,facet|
|
|
111
|
+
facet.include_in_request || (facet.include_in_request.nil? && blacklight_config.add_facet_fields_to_solr_request)
|
|
112
|
+
}.each do |field_name, facet|
|
|
113
|
+
solr_parameters[:facet] ||= true
|
|
114
|
+
|
|
115
|
+
case
|
|
116
|
+
when facet.pivot
|
|
117
|
+
solr_parameters.append_facet_pivot with_ex_local_param(facet.ex, facet.pivot.join(","))
|
|
118
|
+
when facet.query
|
|
119
|
+
solr_parameters.append_facet_query facet.query.map { |k, x| with_ex_local_param(facet.ex, x[:fq]) }
|
|
120
|
+
else
|
|
121
|
+
solr_parameters.append_facet_fields with_ex_local_param(facet.ex, facet.field)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
if facet.sort
|
|
125
|
+
solr_parameters[:"f.#{facet.field}.facet.sort"] = facet.sort
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
if facet.solr_params
|
|
129
|
+
facet.solr_params.each do |k, v|
|
|
130
|
+
solr_parameters[:"f.#{facet.field}.#{k}"] = v
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Support facet paging and 'more'
|
|
135
|
+
# links, by sending a facet.limit one more than what we
|
|
136
|
+
# want to page at, according to configured facet limits.
|
|
137
|
+
solr_parameters[:"f.#{facet.field}.facet.limit"] = (facet_limit_for(field_name) + 1) if facet_limit_for(field_name)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def add_solr_fields_to_query solr_parameters
|
|
142
|
+
blacklight_config.show_fields.select(&method(:should_add_field_to_request?)).each do |field_name, field|
|
|
143
|
+
if field.solr_params
|
|
144
|
+
field.solr_params.each do |k, v|
|
|
145
|
+
solr_parameters[:"f.#{field.field}.#{k}"] = v
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
blacklight_config.index_fields.select(&method(:should_add_field_to_request?)).each do |field_name, field|
|
|
151
|
+
if field.highlight
|
|
152
|
+
solr_parameters[:hl] = true
|
|
153
|
+
solr_parameters.append_highlight_field field.field
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
if field.solr_params
|
|
157
|
+
field.solr_params.each do |k, v|
|
|
158
|
+
solr_parameters[:"f.#{field.field}.#{k}"] = v
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
###
|
|
165
|
+
# copy paging params from BL app over to solr, changing
|
|
166
|
+
# app level per_page and page to Solr rows and start.
|
|
167
|
+
def add_paging_to_solr(solr_params)
|
|
168
|
+
# user-provided parameters should override any default row
|
|
169
|
+
solr_params[:rows] = rows(solr_params[:rows])
|
|
170
|
+
if page > 1
|
|
171
|
+
solr_params[:start] = solr_params[:rows].to_i * (page - 1)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
###
|
|
176
|
+
# copy sorting params from BL app over to solr
|
|
177
|
+
def add_sorting_to_solr(solr_parameters)
|
|
178
|
+
solr_parameters[:sort] = sort unless sort.blank?
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# Remove the group parameter if we've faceted on the group field (e.g. for the full results for a group)
|
|
182
|
+
def add_group_config_to_solr solr_parameters
|
|
183
|
+
if blacklight_params[:f] and blacklight_params[:f][grouped_key_for_results]
|
|
184
|
+
solr_parameters[:group] = false
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def with_ex_local_param(ex, value)
|
|
189
|
+
if ex
|
|
190
|
+
"{!ex=#{ex}}#{value}"
|
|
191
|
+
else
|
|
192
|
+
value
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Look up facet limit for given facet_field. Will look at config, and
|
|
197
|
+
# if config is 'true' will look up from Solr @response if available. If
|
|
198
|
+
# no limit is avaialble, returns nil. Used from #add_facetting_to_solr
|
|
199
|
+
# to supply f.fieldname.facet.limit values in solr request (no @response
|
|
200
|
+
# available), and used in display (with @response available) to create
|
|
201
|
+
# a facet paginator with the right limit.
|
|
202
|
+
def facet_limit_for(facet_field)
|
|
203
|
+
facet = blacklight_config.facet_fields[facet_field]
|
|
204
|
+
return if facet.blank?
|
|
205
|
+
|
|
206
|
+
if facet.limit
|
|
207
|
+
facet.limit == true ? blacklight_config.default_facet_limit : facet.limit
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
##
|
|
212
|
+
# A helper method used for generating solr LocalParams, put quotes
|
|
213
|
+
# around the term unless it's a bare-word. Escape internal quotes
|
|
214
|
+
# if needed.
|
|
215
|
+
def solr_param_quote(val, options = {})
|
|
216
|
+
options[:quote] ||= '"'
|
|
217
|
+
unless val =~ /^[a-zA-Z0-9$_\-\^]+$/
|
|
218
|
+
val = options[:quote] +
|
|
219
|
+
# Yes, we need crazy escaping here, to deal with regexp esc too!
|
|
220
|
+
val.gsub("'", "\\\\\'").gsub('"', "\\\\\"") +
|
|
221
|
+
options[:quote]
|
|
222
|
+
end
|
|
223
|
+
return val
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
private
|
|
227
|
+
|
|
228
|
+
##
|
|
229
|
+
# Convert a facet/value pair into a solr fq parameter
|
|
230
|
+
def facet_value_to_fq_string(facet_field, value)
|
|
231
|
+
facet_config = blacklight_config.facet_fields[facet_field]
|
|
232
|
+
|
|
233
|
+
local_params = []
|
|
234
|
+
local_params << "tag=#{facet_config.tag}" if facet_config and facet_config.tag
|
|
235
|
+
|
|
236
|
+
prefix = ""
|
|
237
|
+
prefix = "{!#{local_params.join(" ")}}" unless local_params.empty?
|
|
238
|
+
|
|
239
|
+
fq = case
|
|
240
|
+
when (facet_config and facet_config.query)
|
|
241
|
+
facet_config.query[value][:fq]
|
|
242
|
+
when (facet_config and facet_config.date)
|
|
243
|
+
# in solr 3.2+, this could be replaced by a !term query
|
|
244
|
+
"#{prefix}#{facet_field}:#{RSolr.solr_escape(value)}"
|
|
245
|
+
when (value.is_a?(DateTime) or value.is_a?(Date) or value.is_a?(Time))
|
|
246
|
+
"#{prefix}#{facet_field}:#{RSolr.solr_escape(value.to_time.utc.strftime("%Y-%m-%dT%H:%M:%SZ"))}"
|
|
247
|
+
when (value.is_a?(TrueClass) or value.is_a?(FalseClass) or value == 'true' or value == 'false'),
|
|
248
|
+
(value.is_a?(Integer) or (value.to_i.to_s == value if value.respond_to? :to_i)),
|
|
249
|
+
(value.is_a?(Float) or (value.to_f.to_s == value if value.respond_to? :to_f))
|
|
250
|
+
"#{prefix}#{facet_field}:#{RSolr.solr_escape(value.to_s)}"
|
|
251
|
+
when value.is_a?(Range)
|
|
252
|
+
"#{prefix}#{facet_field}:[#{value.first} TO #{value.last}]"
|
|
253
|
+
else
|
|
254
|
+
"{!raw f=#{facet_field}#{(" " + local_params.join(" ")) unless local_params.empty?}}#{value}"
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
##
|
|
259
|
+
# The key to use to retrieve the grouped field to display
|
|
260
|
+
def grouped_key_for_results
|
|
261
|
+
blacklight_config.index.group
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
end
|
|
@@ -1,264 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
# Override these methods in your own controller for customizations:
|
|
8
|
-
#
|
|
9
|
-
# class CatalogController < ActionController::Base
|
|
10
|
-
#
|
|
11
|
-
# include Blacklight::Catalog
|
|
12
|
-
#
|
|
13
|
-
# def solr_search_params
|
|
14
|
-
# super.merge :per_page=>10
|
|
15
|
-
# end
|
|
16
|
-
# end
|
|
17
|
-
#
|
|
18
|
-
# Or by including in local extensions:
|
|
19
|
-
# module LocalSolrHelperExtension
|
|
20
|
-
# [ local overrides ]
|
|
21
|
-
# end
|
|
22
|
-
#
|
|
23
|
-
# class CatalogController < ActionController::Base
|
|
24
|
-
#
|
|
25
|
-
# include Blacklight::Catalog
|
|
26
|
-
# include LocalSolrHelperExtension
|
|
27
|
-
#
|
|
28
|
-
# def solr_search_params
|
|
29
|
-
# super.merge :per_page=>10
|
|
30
|
-
# end
|
|
31
|
-
# end
|
|
32
|
-
#
|
|
33
|
-
# Or by using ActiveSupport::Concern:
|
|
34
|
-
#
|
|
35
|
-
# module LocalSolrHelperExtension
|
|
36
|
-
# extend ActiveSupport::Concern
|
|
37
|
-
# include Blacklight::SolrHelper
|
|
38
|
-
#
|
|
39
|
-
# [ local overrides ]
|
|
40
|
-
# end
|
|
41
|
-
#
|
|
42
|
-
# class CatalogController < ApplicationController
|
|
43
|
-
# include LocalSolrHelperExtension
|
|
44
|
-
# include Blacklight::Catalog
|
|
45
|
-
# end
|
|
46
|
-
|
|
47
|
-
module Blacklight::SolrHelper
|
|
48
|
-
extend ActiveSupport::Concern
|
|
49
|
-
extend Deprecation
|
|
50
|
-
self.deprecation_horizon = 'blacklight 6.0'
|
|
51
|
-
|
|
52
|
-
include Blacklight::RequestBuilders
|
|
53
|
-
|
|
54
|
-
##
|
|
55
|
-
# Execute a solr query
|
|
56
|
-
# @see [Blacklight::SolrRepository#send_and_receive]
|
|
57
|
-
# @return [Blacklight::SolrResponse] the solr response object
|
|
58
|
-
def find *args
|
|
59
|
-
solr_params = args.extract_options!
|
|
60
|
-
path = args.first || blacklight_config.solr_path
|
|
61
|
-
|
|
62
|
-
solr_params[:qt] ||= blacklight_config.qt
|
|
63
|
-
|
|
64
|
-
solr_repository.send_and_receive path, solr_params
|
|
65
|
-
end
|
|
66
|
-
deprecation_deprecate :find
|
|
67
|
-
|
|
68
|
-
# returns a params hash for finding a single solr document (CatalogController #show action)
|
|
69
|
-
def solr_doc_params(id=nil)
|
|
70
|
-
default_solr_doc_params(id)
|
|
71
|
-
end
|
|
72
|
-
deprecation_deprecate :solr_doc_params
|
|
73
|
-
|
|
74
|
-
# a solr query method
|
|
75
|
-
# given a user query, return a solr response containing both result docs and facets
|
|
76
|
-
# - mixes in the Blacklight::Solr::SpellingSuggestions module
|
|
77
|
-
# - the response will have a spelling_suggestions method
|
|
78
|
-
# Returns a two-element array (aka duple) with first the solr response object,
|
|
79
|
-
# and second an array of SolrDocuments representing the response.docs
|
|
80
|
-
def get_search_results(user_params = params || {}, extra_controller_params = {})
|
|
81
|
-
solr_response = query_solr(user_params, extra_controller_params)
|
|
82
|
-
|
|
83
|
-
case
|
|
84
|
-
when (solr_response.grouped? && grouped_key_for_results)
|
|
85
|
-
[solr_response.group(grouped_key_for_results), []]
|
|
86
|
-
when (solr_response.grouped? && solr_response.grouped.length == 1)
|
|
87
|
-
[solr_response.grouped.first, []]
|
|
88
|
-
else
|
|
89
|
-
[solr_response, solr_response.documents]
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
# a solr query method
|
|
95
|
-
# given a user query,
|
|
96
|
-
# @return [Blacklight::SolrResponse] the solr response object
|
|
97
|
-
def query_solr(user_params = params || {}, extra_controller_params = {})
|
|
98
|
-
solr_params = self.solr_search_params(user_params).merge(extra_controller_params)
|
|
99
|
-
|
|
100
|
-
solr_repository.search(solr_params)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# a solr query method
|
|
104
|
-
# retrieve a solr document, given the doc id
|
|
105
|
-
# @return [Blacklight::SolrResponse, Blacklight::SolrDocument] the solr response object and the first document
|
|
106
|
-
def get_solr_response_for_doc_id(id=nil, extra_controller_params={})
|
|
107
|
-
if id.nil?
|
|
108
|
-
Deprecation.warn Blacklight::SolrHelper, "Calling #get_solr_response_for_doc_id without an explicit id argument is deprecated"
|
|
109
|
-
id ||= params[:id]
|
|
1
|
+
module Blacklight
|
|
2
|
+
module SolrHelper
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
included do
|
|
5
|
+
include Blacklight::SearchHelper
|
|
6
|
+
Deprecation.warn Blacklight::SolrHelper, "Blacklight::SolrHelper is deprecated; use Blacklight::SearchHelper instead"
|
|
110
7
|
end
|
|
111
|
-
|
|
112
|
-
old_solr_doc_params = Deprecation.silence(Blacklight::SolrHelper) do
|
|
113
|
-
solr_doc_params(id)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
if default_solr_doc_params(id) != old_solr_doc_params
|
|
117
|
-
Deprecation.warn Blacklight::SolrHelper, "The #solr_doc_params method is deprecated. Instead, you should provide a custom SolrRepository implementation for the additional behavior you're offering"
|
|
118
|
-
extra_controller_params = extra_controller_params.merge(old_solr_doc_params)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
solr_response = solr_repository.find id, extra_controller_params
|
|
122
|
-
[solr_response, solr_response.documents.first]
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
##
|
|
126
|
-
# Retrieve a set of documents by id
|
|
127
|
-
# @overload get_solr_response_for_document_ids(ids, extra_controller_params)
|
|
128
|
-
# @overload get_solr_response_for_document_ids(ids, user_params, extra_controller_params)
|
|
129
|
-
def get_solr_response_for_document_ids(ids=[], *args)
|
|
130
|
-
# user_params = params || {}, extra_controller_params = {}
|
|
131
|
-
if args.length == 1
|
|
132
|
-
user_params = params
|
|
133
|
-
extra_controller_params = args.first || {}
|
|
134
|
-
else
|
|
135
|
-
user_params, extra_controller_params = args
|
|
136
|
-
user_params ||= params
|
|
137
|
-
extra_controller_params ||= {}
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
solr_response = query_solr(user_params, extra_controller_params.merge(solr_document_ids_params(ids)))
|
|
141
|
-
|
|
142
|
-
[solr_response, solr_response.documents]
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
# given a field name and array of values, get the matching SOLR documents
|
|
146
|
-
# @return [Blacklight::SolrResponse, Array<Blacklight::SolrDocument>] the solr response object and a list of solr documents
|
|
147
|
-
def get_solr_response_for_field_values(field, values, extra_controller_params = {})
|
|
148
|
-
solr_response = query_solr(params, extra_controller_params.merge(solr_documents_by_field_values_params(field, values)))
|
|
149
|
-
|
|
150
|
-
[solr_response, solr_response.documents]
|
|
151
|
-
end
|
|
152
|
-
deprecation_deprecate :get_solr_response_for_field_values
|
|
153
|
-
|
|
154
|
-
##
|
|
155
|
-
# Get the solr response when retrieving only a single facet field
|
|
156
|
-
# @return [Blacklight::SolrResponse] the solr response
|
|
157
|
-
def get_facet_field_response(facet_field, user_params = params || {}, extra_controller_params = {})
|
|
158
|
-
solr_params = solr_facet_params(facet_field, user_params, extra_controller_params)
|
|
159
|
-
query_solr(user_params, extra_controller_params.merge(solr_facet_params(facet_field, user_params, extra_controller_params)))
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
# a solr query method
|
|
163
|
-
# used to paginate through a single facet field's values
|
|
164
|
-
# /catalog/facet/language_facet
|
|
165
|
-
def get_facet_pagination(facet_field, user_params=params || {}, extra_controller_params={})
|
|
166
|
-
# Make the solr call
|
|
167
|
-
response = get_facet_field_response(facet_field, user_params, extra_controller_params)
|
|
168
|
-
|
|
169
|
-
limit = response.params[:"f.#{facet_field}.facet.limit"].to_s.to_i - 1
|
|
170
|
-
|
|
171
|
-
# Actually create the paginator!
|
|
172
|
-
# NOTE: The sniffing of the proper sort from the solr response is not
|
|
173
|
-
# currently tested for, tricky to figure out how to test, since the
|
|
174
|
-
# default setup we test against doesn't use this feature.
|
|
175
|
-
return Blacklight::Solr::FacetPaginator.new(response.facets.first.items,
|
|
176
|
-
:offset => response.params[:"f.#{facet_field}.facet.offset"],
|
|
177
|
-
:limit => limit,
|
|
178
|
-
:sort => response.params[:"f.#{facet_field}.facet.sort"] || response.params["facet.sort"]
|
|
179
|
-
)
|
|
180
|
-
end
|
|
181
|
-
deprecation_deprecate :get_facet_pagination
|
|
182
|
-
|
|
183
|
-
# a solr query method
|
|
184
|
-
# this is used when selecting a search result: we have a query and a
|
|
185
|
-
# position in the search results and possibly some facets
|
|
186
|
-
# Pass in an index where 1 is the first document in the list, and
|
|
187
|
-
# the Blacklight app-level request params that define the search.
|
|
188
|
-
# @return [Blacklight::SolrDocument, nil] the found document or nil if not found
|
|
189
|
-
def get_single_doc_via_search(index, request_params)
|
|
190
|
-
solr_params = solr_search_params(request_params)
|
|
191
|
-
|
|
192
|
-
solr_params[:start] = (index - 1) # start at 0 to get 1st doc, 1 to get 2nd.
|
|
193
|
-
solr_params[:rows] = 1
|
|
194
|
-
solr_params[:fl] = '*'
|
|
195
|
-
solr_response = solr_repository.search(solr_params)
|
|
196
|
-
solr_response.documents.first
|
|
197
|
-
end
|
|
198
|
-
deprecation_deprecate :get_single_doc_via_search
|
|
199
|
-
|
|
200
|
-
# Get the previous and next document from a search result
|
|
201
|
-
# @return [Blacklight::SolrResponse, Array<Blacklight::SolrDocument>] the solr response and a list of the first and last document
|
|
202
|
-
def get_previous_and_next_documents_for_search(index, request_params, extra_controller_params={})
|
|
203
|
-
|
|
204
|
-
solr_response = query_solr(request_params, extra_controller_params.merge(previous_and_next_document_params(index)))
|
|
205
|
-
|
|
206
|
-
document_list = solr_response.documents
|
|
207
|
-
|
|
208
|
-
# only get the previous doc if there is one
|
|
209
|
-
prev_doc = document_list.first if index > 0
|
|
210
|
-
next_doc = document_list.last if (index + 1) < solr_response.total
|
|
211
|
-
|
|
212
|
-
[solr_response, [prev_doc, next_doc]]
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
# a solr query method
|
|
216
|
-
# does a standard search but returns a simplified object.
|
|
217
|
-
# an array is returned, the first item is the query string,
|
|
218
|
-
# the second item is an other array. This second array contains
|
|
219
|
-
# all of the field values for each of the documents...
|
|
220
|
-
# where the field is the "field" argument passed in.
|
|
221
|
-
def get_opensearch_response(field=nil, request_params = params || {}, extra_controller_params={})
|
|
222
|
-
field ||= blacklight_config.view_config('opensearch').title_field
|
|
223
|
-
|
|
224
|
-
response = query_solr(request_params, solr_opensearch_params(field).merge(extra_controller_params))
|
|
225
|
-
|
|
226
|
-
[response.params[:q], response.documents.flat_map {|doc| doc[field] }.uniq]
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
##
|
|
230
|
-
# The key to use to retrieve the grouped field to display
|
|
231
|
-
def grouped_key_for_results
|
|
232
|
-
blacklight_config.index.group
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
def solr_repository
|
|
236
|
-
@solr_repository ||= Blacklight::SolrRepository.new(blacklight_config)
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
def blacklight_solr
|
|
240
|
-
solr_repository.blacklight_solr
|
|
241
|
-
end
|
|
242
|
-
deprecation_deprecate :blacklight_solr
|
|
243
|
-
|
|
244
|
-
private
|
|
245
|
-
|
|
246
|
-
##
|
|
247
|
-
# @deprecated
|
|
248
|
-
def default_solr_doc_params(id=nil)
|
|
249
|
-
id ||= params[:id]
|
|
250
|
-
|
|
251
|
-
# add our document id to the document_unique_id_param query parameter
|
|
252
|
-
p = blacklight_config.default_document_solr_params.merge({
|
|
253
|
-
# this assumes the request handler will map the unique id param
|
|
254
|
-
# to the unique key field using either solr local params, the
|
|
255
|
-
# real-time get handler, etc.
|
|
256
|
-
blacklight_config.document_unique_id_param => id
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
p[:qt] ||= blacklight_config.document_solr_request_handler
|
|
260
|
-
|
|
261
|
-
p
|
|
262
8
|
end
|
|
263
|
-
|
|
264
9
|
end
|