Class: Riddle::Client::Filter
- Inherits:
-
Object
- Object
- Riddle::Client::Filter
- Defined in:
- lib/riddle/client/filter.rb,
lib/riddle/0.9.9/client/filter.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #exclude? ⇒ Boolean
-
#initialize(attribute, values, exclude = false) ⇒ Filter
constructor
Attribute name, values (which can be an array or a range), and whether the filter should be exclusive.
-
#query_message ⇒ Object
Returns the message for this filter to send to the Sphinx service.
Constructor Details
#initialize(attribute, values, exclude = false) ⇒ Filter
Attribute name, values (which can be an array or a range), and whether the filter should be exclusive.
10 11 12 |
# File 'lib/riddle/client/filter.rb', line 10 def initialize(attribute, values, exclude=false) @attribute, @values, @exclude = attribute, values, exclude end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
6 7 8 |
# File 'lib/riddle/client/filter.rb', line 6 def attribute @attribute end |
#exclude ⇒ Object
Returns the value of attribute exclude.
6 7 8 |
# File 'lib/riddle/client/filter.rb', line 6 def exclude @exclude end |
#values ⇒ Object
Returns the value of attribute values.
6 7 8 |
# File 'lib/riddle/client/filter.rb', line 6 def values @values end |
Instance Method Details
#exclude? ⇒ Boolean
14 15 16 |
# File 'lib/riddle/client/filter.rb', line 14 def exclude? self.exclude end |
#query_message ⇒ Object
Returns the message for this filter to send to the Sphinx service
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 |
# File 'lib/riddle/client/filter.rb', line 19 def = Message.new .append_string self.attribute.to_s case self.values when Range if self.values.first.is_a?(Float) && self.values.last.is_a?(Float) .append_int FilterTypes[:float_range] .append_floats self.values.first, self.values.last else .append_int FilterTypes[:range] append_integer_range , self.values end when Array if self.values.first.is_a?(Float) && self.values.length == 1 .append_int FilterTypes[:float_range] .append_floats self.values.first, self.values.first else .append_int FilterTypes[:values] .append_int self.values.length append_array , self.values end end .append_int self.exclude? ? 1 : 0 .to_s end |