Class: FacetFilter
- Inherits:
-
Struct
- Object
- Struct
- FacetFilter
- Includes:
- HandleFaceting, ManipulateNode
- Defined in:
- public/app/models/facet_filter.rb
Overview
container for handling facet, filter information
Instance Attribute Summary collapse
-
#default_types ⇒ Object
Returns the value of attribute default_types.
-
#facet_set_arr ⇒ Object
Returns the value of attribute facet_set_arr.
-
#facet_types ⇒ Object
Returns the value of attribute facet_types.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#get_facet_types ⇒ Object
an array of strings for asking for filtering.
-
#get_filter_hash(url = nil) ⇒ Object
returns a hash of arrays of hashes representing the selected filters and values, with filter field as the key in the top-level hash, the values being arrays of selections within that filter, each of which is then a hash where pt as the printable field label, pv as the printable value, v as the value of the filter.
-
#get_filter_query ⇒ Object
returns an AdvancedQueryBuilder with the filters worked in.
-
#get_filter_url_params ⇒ Object
-
#initialize(default_types, fields = [], values = []) ⇒ FacetFilter
constructor
A new instance of FacetFilter.
Methods included from HandleFaceting
#fetch_only_facets, #get_pretty_facet_value, #strip_facets
Methods included from ManipulateNode
#inheritance, #process_mixed_content, #strip_mixed_content
Constructor Details
#initialize(default_types, fields = [], values = []) ⇒ FacetFilter
Returns a new instance of FacetFilter.
6 7 8 9 10 11 12 13 |
# File 'public/app/models/facet_filter.rb', line 6 def initialize(default_types, fields = [], values=[]) self.default_types = default_types || [] self.fields = Array.new(fields || []) self.values = Array.new(values || []) self.facet_types = default_types Rails.logger.debug("Default: #{default_types} fields: #{fields} facet_types: #{self.facet_types}") self.facet_set_arr = [] end |
Instance Attribute Details
#default_types ⇒ Object
Returns the value of attribute default_types
2 3 4 |
# File 'public/app/models/facet_filter.rb', line 2 def default_types @default_types end |
#facet_set_arr ⇒ Object
Returns the value of attribute facet_set_arr
2 3 4 |
# File 'public/app/models/facet_filter.rb', line 2 def facet_set_arr @facet_set_arr end |
#facet_types ⇒ Object
Returns the value of attribute facet_types
2 3 4 |
# File 'public/app/models/facet_filter.rb', line 2 def facet_types @facet_types end |
#fields ⇒ Object
Returns the value of attribute fields
2 3 4 |
# File 'public/app/models/facet_filter.rb', line 2 def fields @fields end |
#values ⇒ Object
Returns the value of attribute values
2 3 4 |
# File 'public/app/models/facet_filter.rb', line 2 def values @values end |
Instance Method Details
#get_facet_types ⇒ Object
an array of strings for asking for filtering
16 17 18 |
# File 'public/app/models/facet_filter.rb', line 16 def get_facet_types self.facet_types end |
#get_filter_hash(url = nil) ⇒ Object
returns a hash of arrays of hashes representing the selected filters and values, with filter field as the key in the top-level hash, the values being arrays of selections within that filter, each of which is then a hash where pt as the printable field label, pv as the printable value, v as the value of the filter
36 37 38 39 40 41 42 43 44 45 46 |
# File 'public/app/models/facet_filter.rb', line 36 def get_filter_hash(url = nil) fh = {} self.fields.zip(self.values) do |k, v| pt = I18n.t("search_results.filter.#{k}") pv = get_pretty_facet_value(k, v.sub(/"(.*)"/, '\1')) uri = (url)? url.sub("&filter_fields[]=#{k}&filter_values[]=#{CGI.escape(v)}", "") : '' fh[k] ||= [] fh[k].push({'v' => v, 'pv' => pv, 'pt' => pt, 'uri' => uri }) end fh end |
#get_filter_query ⇒ Object
returns an AdvancedQueryBuilder with the filters worked in.
21 22 23 24 25 |
# File 'public/app/models/facet_filter.rb', line 21 def get_filter_query builder = AdvancedQueryBuilder.new self.fields.zip(self.values) {|field, value| builder.and(field, value) } builder end |
#get_filter_url_params ⇒ Object
27 28 29 30 31 |
# File 'public/app/models/facet_filter.rb', line 27 def get_filter_url_params param = "" self.fields.zip(values) {|field, value| param += "&filter_fields[]=#{field}&filter_values[]=#{CGI.escape(value)}" } param end |