Class: Riddle::Client::Filter
- Inherits:
-
Object
- Object
- Riddle::Client::Filter
- Defined in:
- lib/riddle/client/filter.rb
Overview
Used for querying Sphinx.
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.
9 10 11 |
# File 'lib/riddle/client/filter.rb', line 9 def initialize(attribute, values, exclude=false) @attribute, @values, @exclude = attribute, values, exclude end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
5 6 7 |
# File 'lib/riddle/client/filter.rb', line 5 def attribute @attribute end |
#exclude ⇒ Object
Returns the value of attribute exclude.
5 6 7 |
# File 'lib/riddle/client/filter.rb', line 5 def exclude @exclude end |
#values ⇒ Object
Returns the value of attribute values.
5 6 7 |
# File 'lib/riddle/client/filter.rb', line 5 def values @values end |
Instance Method Details
#exclude? ⇒ Boolean
13 14 15 |
# File 'lib/riddle/client/filter.rb', line 13 def exclude? self.exclude end |
#query_message ⇒ Object
Returns the message for this filter to send to the Sphinx service
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 |
# File 'lib/riddle/client/filter.rb', line 18 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_ints self.values.first, self.values.last end when Array .append_int FilterTypes[:values] .append_int self.values.length # using to_f is a hack from the php client - to workaround 32bit # signed ints on x32 platforms .append_ints *self.values.collect { |val| case val when TrueClass 1.0 when FalseClass 0.0 else val.to_f end } end .append_int self.exclude? ? 1 : 0 .to_s end |