Skip to content
Newer
Older
100644 406 lines (346 sloc) 15.9 KB
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
1 # SolrHelper is a controller layer mixin. It is in the controller scope: request params, session etc.
2 #
3 # NOTE: Be careful when creating variables here as they may be overriding something that already exists.
4 # The ActionController docs: http://api.rubyonrails.org/classes/ActionController/Base.html
5 #
6 # Override these methods in your own controller for customizations:
7 #
8 # class CatalogController < ActionController::Base
9 #
10 # include Blacklight::SolrHelper
11 #
12 # def solr_search_params
13 # super.merge :per_page=>10
14 # end
15 #
16 # end
17 #
18 module Blacklight::SolrHelper
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
19 MaxPerPage = 100
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
20 # When a request for a single solr document by id
21 # is not successful, raise this:
22 class InvalidSolrID < RuntimeError; end
b3de780 @jkeck Moving facet_limit_for and facet_limit_hash methods into SolrHelper.
jkeck authored Oct 12, 2010
23
210cbdb @jrochkind Make solr_search_params_logic a class method.
jrochkind authored Apr 6, 2011
24 def self.included(klass)
25 if klass.respond_to?(:helper_method)
26 klass.helper_method(:facet_limit_hash)
27 klass.helper_method(:facet_limit_for)
b3de780 @jkeck Moving facet_limit_for and facet_limit_hash methods into SolrHelper.
jkeck authored Oct 12, 2010
28 end
210cbdb @jrochkind Make solr_search_params_logic a class method.
jrochkind authored Apr 6, 2011
29
30 # We want to install a class-level place to keep
31 # solr_search_params_logic method names. Compare to before_filter,
32 # similar design. Since we're a module, we have to add it in here.
33 # There are too many different semantic choices in ruby 'class variables',
34 # we choose this one for now, supplied by Rails.
35 klass.class_inheritable_accessor :solr_search_params_logic
36 # Set defaults. Each symbol identifies a _method_ that must be in
37 # this class, taking two parameters (solr_parameters, user_parameters)
38 # Can be changed in local apps or by plugins, eg:
39 # CatalogController.include ModuleDefiningNewMethod
40 # CatalogController.solr_search_params_logic << :new_method
41 # CatalogController.solr_search_params_logic.delete(:we_dont_want)
2349073 @jrochkind new param mapping method #add_query_to_solr
jrochkind authored Apr 7, 2011
42 klass.solr_search_params_logic = [:default_solr_parameters , :whitelist_user_parameters, :add_query_to_solr, :handle_facet_params, :enforce_max_per_page_limit]
b3de780 @jkeck Moving facet_limit_for and facet_limit_hash methods into SolrHelper.
jkeck authored Oct 12, 2010
43 end
210cbdb @jrochkind Make solr_search_params_logic a class method.
jrochkind authored Apr 6, 2011
44
45
0fb4ca4 @jrochkind first try at LocalParams in #search_helper
jrochkind authored Jun 15, 2010
46 # A helper method used for generating solr LocalParams, put quotes
47 # around the term unless it's a bare-word. Escape internal quotes
48 # if needed.
49 def solr_param_quote(val, options = {})
50 options[:quote] ||= '"'
51 unless val =~ /^[a-zA-Z$_\-\^]+$/
abc3c2f @jrochkind make solr_param_quote method really escape quotes properly, need to E…
jrochkind authored Jun 16, 2010
52 val = options[:quote] +
53 # Yes, we need crazy escaping here, to deal with regexp esc too!
54 val.gsub("'", "\\\\\'").gsub('"', "\\\\\"") +
0fb4ca4 @jrochkind first try at LocalParams in #search_helper
jrochkind authored Jun 15, 2010
55 options[:quote]
56 end
57 return val
58 end
43b2448 @jronallo CODEBASE-275: add method to be a whitelist of parameters which can be…
jronallo authored Dec 13, 2010
59
60 # returns an Array of parameter keys which are valid for passing from the
61 # controller on to the solr search request. Used by #solr_search_params.
62 # This allows for overriding this method to add other parameters to the whitelist.
63 def extra_controller_params_whitelist
64 [:qt, :q, :facets, :page, :per_page, :phrase_filters, :f, :fq, :fl, :sort, :qf, :df]
65 end
210cbdb @jrochkind Make solr_search_params_logic a class method.
jrochkind authored Apr 6, 2011
66
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
67
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
68 # returns a params hash for searching solr.
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
69 # The CatalogController #index action uses this.
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
70 # Solr parameters can come from a number of places. From lowest
71 # precedence to highest:
72 # 1. General defaults in blacklight config (are trumped by)
73 # 2. defaults for the particular search field identified by params[:search_field] (are trumped by)
74 # 3. certain parameters directly on input HTTP query params
75 # * not just any parameter is grabbed willy nilly, only certain ones are allowed by HTTP input)
76 # * for legacy reasons, qt in http query does not over-ride qt in search field definition default.
77 # 4. extra parameters passed in as argument.
78 #
79 # spellcheck.q will be supplied with the [:q] value unless specifically
80 # specified otherwise.
81 #
ee23a74 @jrochkind fq from extra_controller_params merged in, now that we're using fq
jrochkind authored Apr 19, 2010
82 # Incoming parameter :f is mapped to :fq solr parameter.
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
83 def solr_search_params(user_params = params || {})
82c7cae @jrochkind Blacklight.config solr defaults consolidated in [:default_solr_params…
jrochkind authored Aug 19, 2010
84 solr_parameters = {}
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
85 solr_search_params_logic.each do |method_name|
86 send(method_name, solr_parameters, user_params)
87 end
88
89 return solr_parameters
90 end
82c7cae @jrochkind Blacklight.config solr defaults consolidated in [:default_solr_params…
jrochkind authored Aug 19, 2010
91
92
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
93 ####
a04d4a1 @jrochkind make sure default param hash has it's values properly dup'd to avoid …
jrochkind authored Aug 19, 2010
94 # Start with general defaults from BL config. Need to use custom
95 # merge to dup values, to avoid later mutating the original by mistake.
ea59318 @cbeer refactor 'convert_url_parameters_to_solr_parameters' into three diffe…
cbeer authored Apr 6, 2011
96 def default_solr_parameters(solr_parameters, user_params)
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
97 if Blacklight.config[:default_solr_params]
98 Blacklight.config[:default_solr_params].each_pair do |key, value|
99 solr_parameters[key] = value.dup rescue value
100 end
a04d4a1 @jrochkind make sure default param hash has it's values properly dup'd to avoid …
jrochkind authored Aug 19, 2010
101 end
102 end
103
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
104 ###
105 # Merge in certain values from HTTP query itelf
106 ###
ea59318 @cbeer refactor 'convert_url_parameters_to_solr_parameters' into three diffe…
cbeer authored Apr 6, 2011
107 def whitelist_user_parameters solr_parameters, user_params
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
108 # Omit empty strings and nil values.
109 [:facets, :f, :page, :sort, :per_page].each do |key|
110 solr_parameters[key] = user_params[key] unless user_params[key].blank?
111 end
ea59318 @cbeer refactor 'convert_url_parameters_to_solr_parameters' into three diffe…
cbeer authored Apr 6, 2011
112
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
113 # pass through any facet fields from request user_params["facet.field"] to
114 # solr user_params. Used by Stanford for it's "faux hierarchical facets".
115 if user_params.has_key?("facet.field")
116 solr_parameters[:"facet.field"] ||= []
117 solr_parameters[:"facet.field"].concat( [user_params["facet.field"]].flatten ).uniq!
fc7ff79 @jrochkind Move legacy :qt passtrhough into add_query_to_solr block.
jrochkind authored Apr 7, 2011
118 end
89c392e @jrochkind Continue passing app request facet.field onto Solr, but avoid RSolr m…
jrochkind authored Aug 19, 2010
119 end
ea59318 @cbeer refactor 'convert_url_parameters_to_solr_parameters' into three diffe…
cbeer authored Apr 6, 2011
120
2349073 @jrochkind new param mapping method #add_query_to_solr
jrochkind authored Apr 7, 2011
121 ##
122 # Take the user-entered query, and put it in the solr params,
123 # including config's "search field" params for current search field.
124 # also include setting spellcheck.q.
125 def add_query_to_solr(solr_parameters, user_parameters)
126 ###
127 # Merge in search field configured values, if present, over-writing general
128 # defaults
129 ###
fc7ff79 @jrochkind Move legacy :qt passtrhough into add_query_to_solr block.
jrochkind authored Apr 7, 2011
130 # legacy behavior of user param :qt is passed through, but over-ridden
131 # by actual search field config if present. We might want to remove
132 # this legacy behavior at some point. It does not seem to be currently
133 # rspec'd.
134 solr_parameters[:qt] = user_parameters[:qt] if user_parameters[:qt]
135
2349073 @jrochkind new param mapping method #add_query_to_solr
jrochkind authored Apr 7, 2011
136 search_field_def = Blacklight.search_field_def_for_key(user_parameters[:search_field])
137 if (search_field_def)
138 solr_parameters[:qt] = search_field_def[:qt] if search_field_def[:qt]
139 solr_parameters.merge!( search_field_def[:solr_parameters]) if search_field_def[:solr_parameters]
ea59318 @cbeer refactor 'convert_url_parameters_to_solr_parameters' into three diffe…
cbeer authored Apr 6, 2011
140 end
2349073 @jrochkind new param mapping method #add_query_to_solr
jrochkind authored Apr 7, 2011
141
142 ##
143 # Create Solr 'q' including the user-entered q, prefixed by any
144 # solr LocalParams in config, using solr LocalParams syntax.
145 # http://wiki.apache.org/solr/LocalParams
146 ##
ea59318 @cbeer refactor 'convert_url_parameters_to_solr_parameters' into three diffe…
cbeer authored Apr 6, 2011
147 if (search_field_def && hash = search_field_def[:solr_local_parameters])
148 local_params = hash.collect do |key, val|
149 key.to_s + "=" + solr_param_quote(val, :quote => "'")
150 end.join(" ")
2349073 @jrochkind new param mapping method #add_query_to_solr
jrochkind authored Apr 7, 2011
151 solr_parameters[:q] = "{!#{local_params}}#{user_parameters[:q]}"
152 else
153 solr_parameters[:q] = user_parameters[:q] if user_parameters[:q]
ea59318 @cbeer refactor 'convert_url_parameters_to_solr_parameters' into three diffe…
cbeer authored Apr 6, 2011
154 end
2349073 @jrochkind new param mapping method #add_query_to_solr
jrochkind authored Apr 7, 2011
155
156
157 ##
158 # Set Solr spellcheck.q to be original user-entered query, without
159 # our local params, otherwise it'll try and spellcheck the local
160 # params! Unless spellcheck.q has already been set by someone,
161 # respect that.
162 #
163 # TODO: Change calling code to expect this as a symbol instead of
164 # a string, for consistency? :'spellcheck.q' is a symbol. Right now
165 # rspec tests for a string, and can't tell if other code may
166 # insist on a string.
167 solr_parameters["spellcheck.q"] = user_parameters[:q] unless solr_parameters["spellcheck.q"]
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
168 end
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
169
ea59318 @cbeer refactor 'convert_url_parameters_to_solr_parameters' into three diffe…
cbeer authored Apr 6, 2011
170 def handle_facet_params solr_parameters, user_params
171
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
172 # And fix the 'facets' parameter to be the way the solr expects it.
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
173 solr_parameters[:facets] &&= {:fields => solr_parameters[:facets]}
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
174
8fe1ae9 @jrochkind CODEBASE-215 SolrHelper#solr_search_params generates fq itself instea…
jrochkind authored Apr 19, 2010
175 # :fq, map from :f.
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
176 if ( solr_parameters[:f])
8fe1ae9 @jrochkind CODEBASE-215 SolrHelper#solr_search_params generates fq itself instea…
jrochkind authored Apr 19, 2010
177 f_request_params = solr_parameters.delete(:f)
178 solr_parameters[:fq] ||= []
179 f_request_params.each_pair do |facet_field, value_list|
180 value_list.each do |value|
181 solr_parameters[:fq] << "{!raw f=#{facet_field}}#{value}"
182 end
183 end
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
184 end
185
1bcb064 @jrochkind SolrHelper#solr_search_params now includes facet.limit and f.facet_na…
jrochkind authored Mar 8, 2010
186 # Facet 'more' limits. Add +1 to any configured facets limits,
021db3b @jrochkind Facet limit config changed to accept 'true', which will take limit fr…
jrochkind authored Aug 23, 2010
187 facet_limit_hash.each_key do |field_name|
188 next if field_name.nil? # skip the 'default' key
189 next unless (limit = facet_limit_for(field_name))
03dde42 @jkeck Merging cherry_picking branch w/ changes back into master.
jkeck authored Oct 15, 2010
190
1bcb064 @jrochkind SolrHelper#solr_search_params now includes facet.limit and f.facet_na…
jrochkind authored Mar 8, 2010
191 solr_parameters[:"f.#{field_name}.facet.limit"] = (limit + 1)
192 end
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
193 end
194
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
195
196 ###
197 # Sanity/requirements checks.
198 ###
199
200 # limit to MaxPerPage (100). Tests want this to be a string not an integer,
201 # not sure why.
ea59318 @cbeer refactor 'convert_url_parameters_to_solr_parameters' into three diffe…
cbeer authored Apr 6, 2011
202 def enforce_max_per_page_limit solr_parameters, user_params
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
203 solr_parameters[:per_page] = solr_parameters[:per_page].to_i > self.max_per_page ? self.max_per_page.to_s : solr_parameters[:per_page]
204 end
13eac1a @jrochkind solr_search_params looks up values from search field definition, when…
jrochkind authored Dec 29, 2009
205
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
206
207 # a solr query method
208 # given a user query, return a solr response containing both result docs and facets
209 # - mixes in the Blacklight::Solr::SpellingSuggestions module
210 # - the response will have a spelling_suggestions method
295beb9 @jrochkind get_search_results returns a duple of solr_response and solr_documen…
jrochkind authored Dec 2, 2009
211 # Returns a two-element array (aka duple) with first the solr response object,
212 # and second an array of SolrDocuments representing the response.docs
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
213 def get_search_results(user_params = params || {}, extra_controller_params = {})
295beb9 @jrochkind get_search_results returns a duple of solr_response and solr_documen…
jrochkind authored Dec 2, 2009
214
09ea706 @jrochkind print to log at debug-level with benchmark elapsed time of #get_searc…
jrochkind authored Nov 2, 2010
215 # In later versions of Rails, the #benchmark method can do timing
216 # better for us.
217 bench_start = Time.now
218
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
219 solr_response = Blacklight.solr.find( self.solr_search_params(user_params).merge(extra_controller_params))
09ea706 @jrochkind print to log at debug-level with benchmark elapsed time of #get_searc…
jrochkind authored Nov 2, 2010
220
0303489 @cbeer CODEBASE-289: add Solr response context to each SolrDocument instance
cbeer authored Feb 28, 2011
221 document_list = solr_response.docs.collect {|doc| SolrDocument.new(doc, solr_response)}
295beb9 @jrochkind get_search_results returns a duple of solr_response and solr_documen…
jrochkind authored Dec 2, 2009
222
09ea706 @jrochkind print to log at debug-level with benchmark elapsed time of #get_searc…
jrochkind authored Nov 2, 2010
223 Rails.logger.debug("Solr fetch: #{self.class}#get_search_results (#{'%.1f' % ((Time.now.to_f - bench_start.to_f)*1000)}ms)")
295beb9 @jrochkind get_search_results returns a duple of solr_response and solr_documen…
jrochkind authored Dec 2, 2009
224
09ea706 @jrochkind print to log at debug-level with benchmark elapsed time of #get_searc…
jrochkind authored Nov 2, 2010
225 return [solr_response, document_list]
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
226 end
227
228 # returns a params hash for finding a single solr document (CatalogController #show action)
229 # If the id arg is nil, then the value is fetched from params[:id]
230 # This method is primary called by the get_solr_response_for_doc_id method.
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
231 def solr_doc_params(id=nil)
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
232 id ||= params[:id]
233 # just to be consistent with the other solr param methods:
234 {
235 :qt => :document,
236 :id => id
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
237 }
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
238 end
239
240 # a solr query method
241 # retrieve a solr document, given the doc id
242 # TODO: shouldn't hardcode id field; should be setable to unique_key field in schema.xml
243 def get_solr_response_for_doc_id(id=nil, extra_controller_params={})
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
244 solr_response = Blacklight.solr.find solr_doc_params(id).merge(extra_controller_params)
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
245 raise InvalidSolrID.new if solr_response.docs.empty?
0303489 @cbeer CODEBASE-289: add Solr response context to each SolrDocument instance
cbeer authored Feb 28, 2011
246 document = SolrDocument.new(solr_response.docs.first, solr_response)
12f720e Changing get_solr_repsonse_for_doc_id so that it returns both the res…
mpc3c authored Nov 17, 2009
247 [solr_response, document]
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
248 end
249
33d9fb8 @jkeck Changing solr helper method to do one solr query for records in folde…
jkeck authored Oct 12, 2010
250 # given a field name and array of values, get the matching SOLR documents
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
251 def get_solr_response_for_field_values(field, values)
33d9fb8 @jkeck Changing solr helper method to do one solr query for records in folde…
jkeck authored Oct 12, 2010
252 value_str = "(\"" + values.to_a.join("\" OR \"") + "\")"
253 solr_params = {
254 :qt => "standard", # need boolean for OR
255 :q => "#{field}:#{value_str}",
256 'fl' => "*",
257 'facet' => 'false',
258 'spellcheck' => 'false'
eee2486 Adding cherry picking code
mpc3c authored Aug 17, 2010
259 }
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
260 solr_response = Blacklight.solr.find( self.solr_search_params().merge(solr_params) )
0303489 @cbeer CODEBASE-289: add Solr response context to each SolrDocument instance
cbeer authored Feb 28, 2011
261 document_list = solr_response.docs.collect{|doc| SolrDocument.new(doc, solr_response) }
33d9fb8 @jkeck Changing solr helper method to do one solr query for records in folde…
jkeck authored Oct 12, 2010
262 [solr_response,document_list]
eee2486 Adding cherry picking code
mpc3c authored Aug 17, 2010
263 end
264
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
265 # returns a params hash for a single facet field solr query.
3942935 @jrochkind changed Paginator arguments to named arguments using hash for clarity…
jrochkind authored Jan 21, 2010
266 # used primary by the get_facet_pagination method.
f82dd6b @jrochkind catalog/facet request parameters (for sort and offset) need to not co…
jrochkind authored Jan 21, 2010
267 # Looks up Facet Paginator request params from current request
13ca209 @jrochkind SolrHelper#solr_facet_params defaults facet list limit to 20, or allo…
jrochkind authored Mar 9, 2010
268 # params to figure out sort and offset.
269 # Default limit for facet list can be specified by defining a controller
270 # method facet_list_limit, otherwise 20.
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
271 def solr_facet_params(facet_field, user_params=params || {}, extra_controller_params={})
272 input = user_params.deep_merge(extra_controller_params)
2ff8d5a @jrochkind #solr_facet_params first calls #solr_search_params to establish searc…
jrochkind authored Jan 25, 2010
273
274 # First start with a standard solr search params calculations,
275 # for any search context in our request params.
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
276 solr_params = solr_search_params(user_params).merge(extra_controller_params)
382392a @jrochkind Move default solr facet fetch parameters from get_facet_pagination to
jrochkind authored Jan 21, 2010
277
2ff8d5a @jrochkind #solr_facet_params first calls #solr_search_params to establish searc…
jrochkind authored Jan 25, 2010
278 # Now override with our specific things for fetching facet values
96a6b3f @jrochkind facet browse method uses ordinary facet.field solr param, instead of …
jrochkind authored Aug 23, 2010
279 solr_params[:"facet.field"] = facet_field
eec4024 @jrochkind SolrHelper#solr_facet_params needs to set specific field limit with f…
jrochkind authored Mar 9, 2010
280
281 # Need to set as f.facet_field.facet.limit to make sure we
282 # override any field-specific default in the solr request handler.
11528e7 @jrochkind need to add key as a symbol to be sure to over-write key added by ord…
jrochkind authored Mar 9, 2010
283 solr_params[:"f.#{facet_field}.facet.limit"] =
eec4024 @jrochkind SolrHelper#solr_facet_params needs to set specific field limit with f…
jrochkind authored Mar 9, 2010
284 if solr_params["facet.limit"]
5774336 @jrochkind solr_facet_params needs to add 1 to limits
jrochkind authored Mar 9, 2010
285 solr_params["facet.limit"] + 1
eec4024 @jrochkind SolrHelper#solr_facet_params needs to set specific field limit with f…
jrochkind authored Mar 9, 2010
286 elsif respond_to?(:facet_list_limit)
5774336 @jrochkind solr_facet_params needs to add 1 to limits
jrochkind authored Mar 9, 2010
287 facet_list_limit.to_s.to_i + 1
eec4024 @jrochkind SolrHelper#solr_facet_params needs to set specific field limit with f…
jrochkind authored Mar 9, 2010
288 else
5774336 @jrochkind solr_facet_params needs to add 1 to limits
jrochkind authored Mar 9, 2010
289 20 + 1
eec4024 @jrochkind SolrHelper#solr_facet_params needs to set specific field limit with f…
jrochkind authored Mar 9, 2010
290 end
0e36ed0 @jrochkind Blacklight::Solr::Facets::Paginator changed to Blacklight::Solr::Face…
jrochkind authored Mar 9, 2010
291 solr_params['facet.offset'] = input[ Blacklight::Solr::FacetPaginator.request_keys[:offset] ].to_i # will default to 0 if nil
292 solr_params['facet.sort'] = input[ Blacklight::Solr::FacetPaginator.request_keys[:sort] ]
2ff8d5a @jrochkind #solr_facet_params first calls #solr_search_params to establish searc…
jrochkind authored Jan 25, 2010
293 solr_params[:rows] = 0
294
295 return solr_params
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
296 end
297
298 # a solr query method
299 # used to paginate through a single facet field's values
300 # /catalog/facet/language_facet
301 def get_facet_pagination(facet_field, extra_controller_params={})
04614b6 @jrochkind CODEBASE-250: get_facet_pagination should sniff for specific f.fieldn…
jrochkind authored Sep 30, 2010
302
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
303 solr_params = solr_facet_params(facet_field, params, extra_controller_params)
96a6b3f @jrochkind facet browse method uses ordinary facet.field solr param, instead of …
jrochkind authored Aug 23, 2010
304
b3dafde @jrochkind Remove Facets.paginate class method. Put logic directly in
jrochkind authored Jan 21, 2010
305 # Make the solr call
306 response = Blacklight.solr.find(solr_params)
e23341a @jrochkind facet parameters calculate facet limit correctly, also checking for l…
jrochkind authored Mar 15, 2010
307
308 limit =
309 if respond_to?(:facet_list_limit)
310 facet_list_limit.to_s.to_i
311 elsif solr_params[:"f.#{facet_field}.facet.limit"]
312 solr_params[:"f.#{facet_field}.facet.limit"] - 1
313 else
314 nil
315 end
316
4ee7f48 @jrochkind Facet paginator knows about current 'sort'.
jrochkind authored Jan 21, 2010
317
b3dafde @jrochkind Remove Facets.paginate class method. Put logic directly in
jrochkind authored Jan 21, 2010
318 # Actually create the paginator!
04614b6 @jrochkind CODEBASE-250: get_facet_pagination should sniff for specific f.fieldn…
jrochkind authored Sep 30, 2010
319 # NOTE: The sniffing of the proper sort from the solr response is not
320 # currently tested for, tricky to figure out how to test, since the
321 # default setup we test against doesn't use this feature.
0e36ed0 @jrochkind Blacklight::Solr::Facets::Paginator changed to Blacklight::Solr::Face…
jrochkind authored Mar 9, 2010
322 return Blacklight::Solr::FacetPaginator.new(response.facets.first.items,
4ee7f48 @jrochkind Facet paginator knows about current 'sort'.
jrochkind authored Jan 21, 2010
323 :offset => solr_params['facet.offset'],
e23341a @jrochkind facet parameters calculate facet limit correctly, also checking for l…
jrochkind authored Mar 15, 2010
324 :limit => limit,
04614b6 @jrochkind CODEBASE-250: get_facet_pagination should sniff for specific f.fieldn…
jrochkind authored Sep 30, 2010
325 :sort => response["responseHeader"]["params"]["f.#{facet_field}.facet.sort"] || response["responseHeader"]["params"]["facet.sort"]
4ee7f48 @jrochkind Facet paginator knows about current 'sort'.
jrochkind authored Jan 21, 2010
326 )
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
327 end
328
329 # a solr query method
330 # this is used when selecting a search result: we have a query and a
331 # position in the search results and possibly some facets
332 def get_single_doc_via_search(extra_controller_params={})
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
333 solr_params = solr_search_params().merge(extra_controller_params)
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
334 solr_params[:per_page] = 1
8fc9331 @jrochkind get_single_doc_via_search should set solr conventional :rows, not jus…
jrochkind authored Sep 16, 2010
335 solr_params[:rows] = 1
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
336 solr_params[:fl] = '*'
337 Blacklight.solr.find(solr_params).docs.first
338 end
eee2486 Adding cherry picking code
mpc3c authored Aug 17, 2010
339
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
340 # returns a solr params hash
341 # if field is nil, the value is fetched from Blacklight.config[:index][:show_link]
342 # the :fl (solr param) is set to the "field" value.
343 # per_page is set to 10
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
344 def solr_opensearch_params(field=nil)
345 solr_params = solr_search_params
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
346 solr_params[:per_page] = 10
347 solr_params[:fl] = Blacklight.config[:index][:show_link]
348 solr_params
349 end
350
351 # a solr query method
352 # does a standard search but returns a simplified object.
353 # an array is returned, the first item is the query string,
354 # the second item is an other array. This second array contains
355 # all of the field values for each of the documents...
356 # where the field is the "field" argument passed in.
357 def get_opensearch_response(field=nil, extra_controller_params={})
07c14d8 @cbeer one possible refactoring for #solr_search_params in order to split lo…
cbeer authored Apr 5, 2011
358 solr_params = solr_opensearch_params().merge(extra_controller_params)
cfc4743 @g8tor Initial Commit
g8tor authored Oct 30, 2009
359 response = Blacklight.solr.find(solr_params)
360 a = [solr_params[:q]]
361 a << response.docs.map {|doc| doc[solr_params[:fl]].to_s }
362 end
363
03dde42 @jkeck Merging cherry_picking branch w/ changes back into master.
jkeck authored Oct 15, 2010
364
365
366 # Look up facet limit for given facet_field. Will look at config, and
367 # if config is 'true' will look up from Solr @response if available. If
368 # no limit is avaialble, returns nil. Used from #solr_search_params
369 # to supply f.fieldname.facet.limit values in solr request (no @response
370 # available), and used in display (with @response available) to create
371 # a facet paginator with the right limit.
b3de780 @jkeck Moving facet_limit_for and facet_limit_hash methods into SolrHelper.
jkeck authored Oct 12, 2010
372 def facet_limit_for(facet_field)
373 limits_hash = facet_limit_hash
94e11b4 @jkeck Handling case where there are no facet limits set in configuration.
jkeck authored Dec 9, 2010
374 return nil if limits_hash.blank?
03dde42 @jkeck Merging cherry_picking branch w/ changes back into master.
jkeck authored Oct 15, 2010
375
b3de780 @jkeck Moving facet_limit_for and facet_limit_hash methods into SolrHelper.
jkeck authored Oct 12, 2010
376 limit = limits_hash[facet_field]
03dde42 @jkeck Merging cherry_picking branch w/ changes back into master.
jkeck authored Oct 15, 2010
377
378 if ( limit == true && @response &&
379 @response["responseHeader"] &&
380 @response["responseHeader"]["params"])
381 limit =
382 @response["responseHeader"]["params"]["f.#{facet_field}.facet.limit"] ||
383 @response["responseHeader"]["params"]["facet.limit"]
384 limit = (limit.to_i() -1) if limit
385 limit = nil if limit == -2 # -1-1==-2, unlimited.
386 elsif limit == true
387 limit = nil
388 end
b3de780 @jkeck Moving facet_limit_for and facet_limit_hash methods into SolrHelper.
jkeck authored Oct 12, 2010
389
390 return limit
391 end
03dde42 @jkeck Merging cherry_picking branch w/ changes back into master.
jkeck authored Oct 15, 2010
392
b3de780 @jkeck Moving facet_limit_for and facet_limit_hash methods into SolrHelper.
jkeck authored Oct 12, 2010
393 # Returns complete hash of key=facet_field, value=limit.
394 # Used by SolrHelper#solr_search_params to add limits to solr
395 # request for all configured facet limits.
396 def facet_limit_hash
94e11b4 @jkeck Handling case where there are no facet limits set in configuration.
jkeck authored Dec 9, 2010
397 Blacklight.config[:facet][:limits] || {}
b3de780 @jkeck Moving facet_limit_for and facet_limit_hash methods into SolrHelper.
jkeck authored Oct 12, 2010
398 end
8418248 use the new max_per_page method to abstract MaxPerPage, making it eas…
Chris Beer authored Oct 27, 2010
399
400 def max_per_page
401 MaxPerPage
402 end
b3de780 @jkeck Moving facet_limit_for and facet_limit_hash methods into SolrHelper.
jkeck authored Oct 12, 2010
403
404
07146df removing ignored statemenet from solr_doc_params, and adding extra_co…
Chris Beer authored Oct 26, 2010
405 end
Something went wrong with that request. Please try again.