Module: BlacklightRangeLimit::RangeLimitBuilder

Extended by:
ActiveSupport::Concern
Includes:
SegmentCalculation
Defined in:
lib/blacklight_range_limit/range_limit_builder.rb

Instance Method Summary collapse

Instance Method Details

#add_range_limit_params(solr_params) ⇒ Object

Method added to to fetch proper things for date ranges.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/blacklight_range_limit/range_limit_builder.rb', line 14

def add_range_limit_params(solr_params)
   ranged_facet_configs =
     blacklight_config.facet_fields.select { |key, config| config.range }
   # In ruby 1.8, hash.select returns an array of pairs, in ruby 1.9
   # it returns a hash. Turn it into a hash either way.
   ranged_facet_configs = Hash[ ranged_facet_configs ] unless ranged_facet_configs.kind_of?(Hash)

   ranged_facet_configs.each_pair do |field_key, config|
    solr_params["stats"] = "true"
    solr_params["stats.field"] ||= []
    solr_params["stats.field"] << config.field

    range_config = BlacklightRangeLimit.range_config(blacklight_config, config.field)

    hash =  blacklight_params["range"] && blacklight_params["range"][field_key] ?
      blacklight_params["range"][field_key] :
      {}

    if !hash["missing"].blank?
      # missing specified in request params
      solr_params[:fq] ||= []
      solr_params[:fq] << "-#{config.field}:[* TO *]"

    elsif !(hash["begin"].blank? && hash["end"].blank?)
      # specified in request params, begin and/or end, might just have one
      start = hash["begin"].blank? ? "*" : hash["begin"]
      finish = hash["end"].blank? ? "*" : hash["end"]

      solr_params[:fq] ||= []
      solr_params[:fq] << "#{config.field}: [#{start} TO #{finish}]"

      if (range_config[:segments] != false && start != "*" && finish != "*")
        # Add in our calculated segments, can only do with both boundaries.
        add_range_segments_to_solr!(solr_params, field_key, start.to_i, finish.to_i)
      end

    elsif (range_config[:segments] != false &&
           boundaries = range_config[:assumed_boundaries])
      # assumed_boundaries in config
      add_range_segments_to_solr!(solr_params, field_key, boundaries[0], boundaries[1])
    end
  end

  return solr_params
end

#fetch_specific_range_limit(solr_params) ⇒ Object

Another processing method, this one is NOT included in default processing chain, it is specifically swapped in *instead of* add_range_limit_params for certain ajax requests that only want to fetch range limit segments for ONE field.

It turns off facetting and sets rows to 0 as well, only results for single specified field are needed.

Specified field and parameters are specified in incoming parameters range_field, range_start, range_end


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/blacklight_range_limit/range_limit_builder.rb', line 71

def fetch_specific_range_limit(solr_params)
  field_key = blacklight_params[:range_field] # what field to fetch for
  start = blacklight_params[:range_start].to_i
  finish = blacklight_params[:range_end].to_i

  add_range_segments_to_solr!(solr_params, field_key, start, finish )

  # Remove all field faceting for efficiency, we won't be using it.
  solr_params.delete("facet.field")
  solr_params.delete("facet.field".to_sym)

  # We don't need any actual rows either
  solr_params[:rows] = 0      

  return solr_params
end