Module: BlacklightRangeLimit::ControllerOverride

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

Instance Method Summary collapse

Instance Method Details

#add_range_limit_params(solr_params, req_params) ⇒ Object

Method added to solr_search_params_logic to fetch proper things for date ranges.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/blacklight_range_limit/controller_override.rb', line 63

def add_range_limit_params(solr_params, req_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 |solr_field, config|
    solr_params["stats"] = "true"
    solr_params["stats.field"] ||= []
    solr_params["stats.field"] << solr_field    
  
    hash =  req_params["range"] && req_params["range"][solr_field] ?
      req_params["range"][solr_field] :
      {}
      
    if !hash["missing"].blank?
      # missing specified in request params
      solr_params[:fq] ||= []
      solr_params[:fq] << "-#{solr_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] << "#{solr_field}: [#{start} TO #{finish}]"
      
      if (config.segments != false && start != "*" && finish != "*")
        # Add in our calculated segments, can only do with both boundaries.
        add_range_segments_to_solr!(solr_params, solr_field, start.to_i, finish.to_i)
      end
      
    elsif (config.segments != false &&
           boundaries = config.assumed_boundaries)
      # assumed_boundaries in config
      add_range_segments_to_solr!(solr_params, solr_field, boundaries[0], boundaries[1])
    end
  end
  
  return solr_params
end

#range_config(solr_field) ⇒ Object

Returns range config hash for named solr field. Returns false if not configured. Returns hash even if configured to ‘true’ for consistency.



110
111
112
113
114
115
116
117
118
# File 'lib/blacklight_range_limit/controller_override.rb', line 110

def range_config(solr_field)    
  field = blacklight_config.facet_fields[solr_field]
  return false unless field.range

  config = field.range
  config = {} if config === true

  config
end

#range_limitObject

Action method of our own! Delivers a partial that’s a display of a single fields range facets. Used when we need a second Solr query to get range facets, after the first found min/max from result set.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/blacklight_range_limit/controller_override.rb', line 36

def range_limit
  solr_field = params[:range_field] # what field to fetch for
  start = params[:range_start].to_i
  finish = params[:range_end].to_i
  
  solr_params = solr_search_params(params)
  
  # Remove all field faceting for efficiency, we won't be using it.
  solr_params.delete("facet.field")
  solr_params.delete("facet.field".to_sym)
  
  add_range_segments_to_solr!(solr_params, solr_field, start, finish )
  # We don't need any actual rows or facets, we're just going to look
  # at the facet.query's
  solr_params[:rows] = 0
  solr_params[:facets] = nil
  solr_params[:qt] ||= blacklight_config.qt
  # Not really any good way to turn off facet.field's from the solr default,
  # no big deal it should be well-cached at this point.

  @response = Blacklight.solr.get( blacklight_config.solr_path, :params => solr_params )

  render('blacklight_range_limit/range_segments', :locals => {:solr_field => solr_field}, :layout => !request.xhr?)
end