Module: Isomorfeus::Ferret::FieldSymbolMethods

Included in:
FieldSymbol, Symbol
Defined in:
lib/isomorfeus/ferret/field_symbol.rb

Overview

The FieldSymbolMethods module contains the methods that are added to both the Symbol class and the FieldSymbol class. These methods allow you to easily set the type of a field by calling a method on a symbol.

Right now this is only useful for Sorting and grouping, but some day Ferret may have typed fields, in which case these this methods will come in handy.

The available types are specified in Ferret::FIELD_TYPES.

Examples

index.search(query, :sort => :title.string.desc)

index.search(query, :sort => [:price.float, :count.integer.desc])

index.search(query, :group_by => :catalogue.string)

Note

If you set the field type multiple times, the last type specified will be the type used. For example;

puts :title.integer.float.byte.string.type.inspect # => :string

Calling #desc twice will set desc? to false

puts :title.desc?           # => false
puts :title.desc.desc?      # => true
puts :title.desc.desc.desc? # => false

Instance Method Summary collapse

Instance Method Details

#descObject

Set a field to be a descending field. This only makes sense in sort specifications.



48
49
50
51
52
# File 'lib/isomorfeus/ferret/field_symbol.rb', line 48

def desc
  fsym = FieldSymbol.new(self, respond_to?(:desc?) ? !desc? : true)
  fsym.type = respond_to?(:type) ? type : nil
  fsym
end

#desc?Boolean

Return whether or not this field should be a descending field

Returns:

  • (Boolean)


55
56
57
# File 'lib/isomorfeus/ferret/field_symbol.rb', line 55

def desc?
  self.class == FieldSymbol and @desc == true
end

#typeObject

Return the type of this field



60
61
62
# File 'lib/isomorfeus/ferret/field_symbol.rb', line 60

def type
  self.class == FieldSymbol ? @type : nil
end