Module: Mongoid::FTS
- Extended by:
- Util
- Defined in:
- lib/mongoid-fts.rb,
lib/mongoid-fts/raw.rb,
lib/mongoid-fts/able.rb,
lib/mongoid-fts/util.rb,
lib/mongoid-fts/error.rb,
lib/mongoid-fts/index.rb,
lib/mongoid-fts/rails.rb,
lib/mongoid-fts/results.rb,
lib/mongoid-fts/stemming.rb
Defined Under Namespace
Modules: Able, Stemming, Util
Classes: Engine, Error, Index, Raw, Results
Class Method Summary
collapse
Methods included from Util
boolean_and, boolean_or, chars, connect!, create_indexes, destroy_all, enable!, find_in_batches, find_or_create, fts_models, fuzzy, index, index!, list_of_strings, literals_for, models, ngrams_for, normalized_array, reset!, session, session=, setup!, stems_for, stopword?, strip, terms_for, unidecode, unindex, unindex!, utf8ify, words_for
Class Method Details
._search(*args) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/mongoid-fts.rb', line 88
def FTS._search(*args)
options = Map.options_for!(args)
literals = Coerce.list_of_strings(options[:literals], options[:literal])
terms = Coerce.list_of_strings(options[:terms], options[:searches], options[:term], options[:search], args)
fuzzy = Coerce.list_of_strings(options[:fuzzy])
operator =
case
when options[:all] || options[:operator].to_s == 'and'
if options[:all] != true
terms.push(*Coerce.list_of_strings(options[:all]))
end
:and
when options[:any] || options[:operator].to_s == 'or'
if options[:any] != true
terms.push(*Coerce.list_of_strings(options[:any]))
end
:or
else
:and
end
if fuzzy.empty?
fuzzy = terms
end
searches = []
strings =
[
FTS.literals_for(literals),
FTS.terms_for(terms)
].uniq
search =
case operator
when :and
FTS.boolean_and(strings)
when :or
FTS.boolean_or(strings)
end
searches.push(search)
search = FTS.boolean_or(FTS.fuzzy_for(fuzzy))
searches.push(search)
text = options.delete(:text) || Index.default_collection_name.to_s
limit = [Integer(options.delete(:limit) || 128), 1].max
models = [options.delete(:models), options.delete(:model)].flatten.compact
models = FTS.models if models.empty?
last = searches.size - 1
searches.each_with_index do |search, i|
_searches =
if search.strip.empty?
[]
else
models.map do |model|
context_type = model.name.to_s
cmd = Hash.new
cmd[:text] ||= text
cmd[:limit] ||= limit
(cmd[:search] ||= '') << search
cmd[:project] ||= {'_id' => 1, 'context_type' => 1, 'context_id' => 1}
cmd[:filter] ||= {'context_type' => context_type}
Map.for(session.command(cmd)).tap do |_search|
_search[:_model] = model
_search[:_cmd] = cmd
end
end
end
raw = Raw.new(_searches, :_search => search, :_text => text, :_limit => limit, :_models => models)
return raw if(i == last || !raw.empty?)
end
end
|
.able ⇒ Object
64
65
66
|
# File 'lib/mongoid-fts/able.rb', line 64
def FTS.able
Able
end
|
.dependencies ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/mongoid-fts.rb', line 12
def dependencies
{
'mongoid' => [ 'mongoid' , '~> 3.1' ] ,
'map' => [ 'map' , '~> 6.5' ] ,
'coerce' => [ 'coerce' , '~> 0.0' ] ,
'unicode_utils' => [ 'unicode_utils' , '~> 1.4' ] ,
'stringex' => [ 'stringex' , '~> 2.0' ] ,
'fast_stemmer' => [ 'fast-stemmer' , '~> 1.0' ] ,
}
end
|
.included(other) ⇒ Object
190
191
192
193
|
# File 'lib/mongoid-fts.rb', line 190
def FTS.included(other)
other.send(:include, Able)
super
end
|
.libdir(*args, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/mongoid-fts.rb', line 23
def libdir(*args, &block)
@libdir ||= File.expand_path(__FILE__).sub(/\.rb$/,'')
args.empty? ? @libdir : File.join(@libdir, *args)
ensure
if block
begin
$LOAD_PATH.unshift(@libdir)
block.call()
ensure
$LOAD_PATH.shift()
end
end
end
|
.load(*libs) ⇒ Object
37
38
39
40
|
# File 'lib/mongoid-fts.rb', line 37
def load(*libs)
libs = libs.join(' ').scan(/[^\s+]+/)
libdir{ libs.each{|lib| Kernel.load(lib) } }
end
|
.search(*args) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/mongoid-fts.rb', line 80
def FTS.search(*args)
options = Map.options_for(args)
_searches = FTS._search(*args)
Results.new(_searches)
end
|
.version ⇒ Object
8
9
10
|
# File 'lib/mongoid-fts.rb', line 8
def version
const_get(:Version)
end
|