Module: Blacklight::RequestBuilders

Extended by:
ActiveSupport::Concern
Included in:
SearchHelper
Defined in:
app/controllers/concerns/blacklight/request_builders.rb

Constant Summary collapse

DEFAULT_FACET_LIMIT =
10

Instance Method Summary collapse

Instance Method Details

#facet_limit_for(facet_field) ⇒ Object

Look up facet limit for given facet_field. Will look at config, and if config is 'true' will look up from Solr @response if available. If no limit is avaialble, returns nil. Used from #add_facetting_to_solr to supply f.fieldname.facet.limit values in solr request (no @response available), and used in display (with @response available) to create a facet paginator with the right limit.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/concerns/blacklight/request_builders.rb', line 58

def facet_limit_for(facet_field)
  facet = blacklight_config.facet_fields[facet_field]
  return if facet.blank?

  if facet.limit and @response and @response.aggregations[facet.field]
    limit = @response.aggregations[facet.field].limit

    if limit.nil? # we didn't get or a set a limit, so infer one.
      facet.limit if facet.limit != true
    elsif limit == -1 # limit -1 is solr-speak for unlimited
      nil
    else
      limit.to_i - 1 # we added 1 to find out if we needed to paginate
    end
  elsif facet.limit
    facet.limit == true ? DEFAULT_FACET_LIMIT : facet.limit
  end
end

#previous_and_next_document_params(index, window = 1) ⇒ Object

Pagination parameters for selecting the previous and next documents out of a result set.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/concerns/blacklight/request_builders.rb', line 31

def previous_and_next_document_params(index, window = 1)
  solr_params = blacklight_config.document_pagination_params.dup

  if solr_params.empty?
    solr_params[:fl] = '*'
  end

  if index > 0
    solr_params[:start] = index - window # get one before
    solr_params[:rows] = 2*window + 1 # and one after
  else
    solr_params[:start] = 0 # there is no previous doc
    solr_params[:rows] = 2*window # but there should be one after
  end

  solr_params[:facet] = false
  solr_params
end

#search_builderObject



15
16
17
# File 'app/controllers/concerns/blacklight/request_builders.rb', line 15

def search_builder
  search_builder_class.new(self)
end

#solr_opensearch_params(field) ⇒ Object

Opensearch autocomplete parameters for plucking a field's value from the results



21
22
23
24
25
26
# File 'app/controllers/concerns/blacklight/request_builders.rb', line 21

def solr_opensearch_params(field)
  solr_params = {}
  solr_params[:rows] ||= 10
  solr_params[:fl] = field || blacklight_config.view_config('opensearch').title_field
  solr_params
end