Module: MongoidXapian::ClassMethods

Defined in:
lib/mongoid-xapian.rb

Instance Method Summary collapse

Instance Method Details

#fti(*args) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/mongoid-xapian.rb', line 79

def fti(*args)
  # make sure id is not in the list
  args.delete(:id)

  # index mongodb' id
  args << :_id
 
  @xapian_options = args.extract_options!
  @xapian_fields = args
end

#search(pattern, opts = {}) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/mongoid-xapian.rb', line 112

def search(pattern, opts = {})
  language = opts.delete(:language) || 'en'
  ids = search_db(language).search(pattern, opts).map do |result|
    result.values[:_id]
  end

  self.where(:_id.in => ids)
end

#search_db(language = "en") ⇒ Object



100
101
102
103
104
105
106
# File 'lib/mongoid-xapian.rb', line 100

def search_db(language = "en")
  XapianFu::XapianDb.new({
    :dir => self.xapian_db_path(language),
    :create => false,
    :store => @xapian_fields
  })
end

#xapian_db(language = "en") ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/mongoid-xapian.rb', line 90

def xapian_db(language = "en")
  @xapian_databases ||= {}

  @xapian_databases[language] ||= XapianFu::XapianDb.new({
    :dir => self.xapian_db_path(language),
    :create => true,
    :store => @xapian_fields
  })
end

#xapian_db_path(language = "en") ⇒ Object



108
109
110
# File 'lib/mongoid-xapian.rb', line 108

def xapian_db_path(language = "en")
  "#{Bundler.root}/xapian/#{self.to_s.underscore}.#{language}.db"
end