module Mongoid::Giza

Module that should be included in a Mongoid::Document in order to

index fields of documents of this class

@example Creating a simple index with a full-text field (named fts) and an

attribute (named attr)
class Person
  include Mongoid::Document
  include Mongoid::Giza

  field :name
  field :age, type: Integer

  sphinx_index do
    field :name
    attribute :age
  end
end

@example Searching the previously defined index for people named John between 18 and 59 years old

results = Person.search do
  fulltext "john"
  with age: 18..59
end

results.first[:Person].first # => First object that matched

Constants

VERSION

Public Instance Methods

generate_sphinx_indexes() click to toggle source

Generates all the dynamic indexes defined on the class for the object

# File lib/mongoid/giza.rb, line 59
def generate_sphinx_indexes
  self.class.dynamic_sphinx_indexes.each do |dynamic_index|
    index = dynamic_index.generate_index(self)
    self.class.generated_sphinx_indexes[index.name] = index
    self.class.giza_configuration.add_index(index, true)
  end
end