Module: Texticle

Defined in:
lib/texticle.rb,
lib/texticle/rails.rb,
lib/texticle/version.rb,
lib/texticle/postgres_module_installer.rb

Defined Under Namespace

Modules: Helper Classes: FullTextIndexer, PostgresModuleInstaller, Railtie

Constant Summary collapse

VERSION =
'2.2.0'

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *search_terms) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/texticle.rb', line 36

def method_missing(method, *search_terms)
  return super if self == ActiveRecord::Base
  if Helper.dynamic_search_method?(method, self.columns)
    exclusive = Helper.exclusive_dynamic_search_method?(method, self.columns)
    columns = exclusive ? Helper.exclusive_dynamic_search_columns(method) : Helper.inclusive_dynamic_search_columns(method)
    metaclass = class << self; self; end
    metaclass.__send__(:define_method, method) do |*args|
      query = columns.inject({}) do |query, column|
        query.merge column => args.shift
      end
      self.send(Helper.search_type(method), query, exclusive)
    end
    __send__(method, *search_terms, exclusive)
  else
    super
  end
rescue ActiveRecord::StatementInvalid
  super
end

Class Method Details

.searchable_languageObject


6
7
8
# File 'lib/texticle.rb', line 6

def self.searchable_language
  'english'
end

.versionObject


6
7
8
# File 'lib/texticle/version.rb', line 6

def self.version
  VERSION
end

Instance Method Details

#advanced_search(query = "", exclusive = true) ⇒ Object


22
23
24
25
26
27
# File 'lib/texticle.rb', line 22

def advanced_search(query = "", exclusive = true)
  exclusive, query = munge_exclusive_and_query(exclusive, query)
  parsed_query_hash = parse_query_hash(query)
  similarities, conditions = advanced_similarities_and_conditions(parsed_query_hash)
  assemble_query(similarities, conditions, exclusive)
end

#basic_search(query = "", exclusive = true) ⇒ Object


15
16
17
18
19
20
# File 'lib/texticle.rb', line 15

def basic_search(query = "", exclusive = true)
  exclusive, query = munge_exclusive_and_query(exclusive, query)
  parsed_query_hash = parse_query_hash(query)
  similarities, conditions = basic_similarities_and_conditions(parsed_query_hash)
  assemble_query(similarities, conditions, exclusive)
end

#fuzzy_search(query = '', exclusive = true) ⇒ Object


29
30
31
32
33
34
# File 'lib/texticle.rb', line 29

def fuzzy_search(query = '', exclusive = true)
  exclusive, query = munge_exclusive_and_query(exclusive, query)
  parsed_query_hash = parse_query_hash(query)
  similarities, conditions = fuzzy_similarities_and_conditions(parsed_query_hash)
  assemble_query(similarities, conditions, exclusive)
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

56
57
58
59
60
61
# File 'lib/texticle.rb', line 56

def respond_to?(method, include_private = false)
  return super if self == ActiveRecord::Base
  Helper.dynamic_search_method?(method, self.columns) or super
rescue StandardError
  super
end

#search(query = "", exclusive = true) ⇒ Object


10
11
12
13
# File 'lib/texticle.rb', line 10

def search(query = "", exclusive = true)
  warn "[DEPRECATION] `search` is deprecated. Please use `advanced_search` instead. At the next major release `search` will become an alias for `basic_search`."
  advanced_search(query, exclusive)
end