Module: Mongoid::Search::ClassMethods

Defined in:
lib/mongoid_search/mongoid_search.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#full_text_search(query, options = {}) ⇒ Object Also known as: csearch, search



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mongoid_search/mongoid_search.rb', line 27

def full_text_search(query, options = {})
  options = extract_options(options)
  attr_accessor :relevance if options[:relevant_search].eql? true

  return (options[:allow_empty_search] ? criteria.all : []) if query.blank?

  if options[:relevant_search]
    search_relevant(query, options)
  else
    search_without_relevance(query, options)
  end
end

#index_keywords!Object

Goes through all documents in the class that includes Mongoid::Search and indexes the keywords.



46
47
48
# File 'lib/mongoid_search/mongoid_search.rb', line 46

def index_keywords!
  all.each { |d| d.index_keywords! ? Log.green('.') : Log.red('F') }
end

#search_in(*args) ⇒ Object

Set a field or a number of fields as sources for search



16
17
18
19
20
21
22
23
24
25
# File 'lib/mongoid_search/mongoid_search.rb', line 16

def search_in(*args)
  args, options = args_and_options(args)
  set_search_fields(options[:index], args)

  field options[:index], type: Array

  index({ options[:index] => 1 }, background: true)

  before_save :set_keywords
end