Class: SolrLite::FacetField

Inherits:
Object
  • Object
show all
Defined in:
lib/facet_field.rb

Defined Under Namespace

Classes: FacetValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, display_value) ⇒ FacetField

Returns a new instance of FacetField.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/facet_field.rb', line 20

def initialize(name, display_value)
  @name = name # field name in Solr
  @title = display_value
  @values = []
  @ranges = []
  @range = false
  @range_start = nil
  @range_end = nil
  @range_gap = nil
  @limit = nil
end

Instance Attribute Details

#limitObject

Returns the value of attribute limit.



16
17
18
# File 'lib/facet_field.rb', line 16

def limit
  @limit
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/facet_field.rb', line 16

def name
  @name
end

#rangeObject

Returns the value of attribute range.



16
17
18
# File 'lib/facet_field.rb', line 16

def range
  @range
end

#range_endObject

Returns the value of attribute range_end.



16
17
18
# File 'lib/facet_field.rb', line 16

def range_end
  @range_end
end

#range_gapObject

Returns the value of attribute range_gap.



16
17
18
# File 'lib/facet_field.rb', line 16

def range_gap
  @range_gap
end

#range_startObject

Returns the value of attribute range_start.



16
17
18
# File 'lib/facet_field.rb', line 16

def range_start
  @range_start
end

#titleObject

Returns the value of attribute title.



16
17
18
# File 'lib/facet_field.rb', line 16

def title
  @title
end

#valuesObject

Returns the value of attribute values.



16
17
18
# File 'lib/facet_field.rb', line 16

def values
  @values
end

Instance Method Details

#add_range(range_start, range_end, count) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/facet_field.rb', line 44

def add_range(range_start, range_end, count)
  text = "#{range_start} - #{range_end}"
  value = FacetValue.new(text, count)
  value.range_start = range_start
  value.range_end = range_end
  @values << value
end

#add_value(text, count) ⇒ Object



40
41
42
# File 'lib/facet_field.rb', line 40

def add_value(text, count)
  @values << FacetValue.new(text, count)
end

#set_add_url_for(value, url) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/facet_field.rb', line 66

def set_add_url_for(value, url)
  @values.each do |v|
    if v.text == value
      v.add_url = url
    end
  end
end

#set_remove_url_for(value, url) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/facet_field.rb', line 58

def set_remove_url_for(value, url)
  @values.each do |v|
    if v.text == value
      v.remove_url = url
    end
  end
end

#set_urls_for(value, add_url, remove_url) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/facet_field.rb', line 74

def set_urls_for(value, add_url, remove_url)
  @values.each do |v|
    if v.text == value
      v.add_url = add_url
      v.remove_url = remove_url
    end
  end
end

#to_qs(text) ⇒ Object



32
33
34
# File 'lib/facet_field.rb', line 32

def to_qs(text)
  "#{@name}|#{CGI.escape(text)}"
end

#to_qs_range(range_start, range_end) ⇒ Object



36
37
38
# File 'lib/facet_field.rb', line 36

def to_qs_range(range_start, range_end)
  "#{@name}^#{range_start},#{range_end}"
end

#value_count(text) ⇒ Object



52
53
54
55
56
# File 'lib/facet_field.rb', line 52

def value_count(text)
  v = @values.find {|v| v.text == text}
  return 0 if v == nil
  v.count
end