Class: Ion::Indices::Text
Instance Attribute Summary
Attributes inherited from Ion::Index
#name, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Ion::Index
del, #initialize
Constructor Details
This class inherits a constructor from Ion::Index
Class Method Details
.deindex(record) ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/ion/indices/text.rb', line 23
def self.deindex(record)
super
refs = references_key(record)
refs.smembers.each do |key|
Ion.redis.zrem(key, record.id)
Ion.redis.del(key) if Ion.redis.zrange(key,0,0).nil?
end
end
|
Instance Method Details
#index(record) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/ion/indices/text.rb', line 11
def index(record)
super
words = index_words(value_for(record).to_s)
refs = references_key(record)
words.each do |word|
k = index_key[word]
refs.sadd k
k.zadd 1, record.id
end
end
|
#index_words(str) ⇒ Object
3
4
5
|
# File 'lib/ion/indices/text.rb', line 3
def index_words(str)
Stringer.keywords str
end
|
#search(what, args = {}) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/ion/indices/text.rb', line 32
def search(what, args={})
super
words = search_words(what)
keys = words.map { |word| index_key[word] }
w = keys.map { 0 }; w[0] = 1
Ion.intersect keys, weights: w
end
|
#search_words(str) ⇒ Object
7
8
9
|
# File 'lib/ion/indices/text.rb', line 7
def search_words(str)
index_words str
end
|