Class: Fuzzzy::Soundex::Indexer

Inherits:
Base show all
Includes:
Indexer
Defined in:
lib/fuzzzy/methods/soundex/indexer.rb

Constant Summary

Constants included from Redis

Redis::INDEX_KEY

Instance Attribute Summary

Attributes inherited from MethodBase

#context

Instance Method Summary collapse

Methods included from Indexer

#delete_dictionary, #save_dictionary

Methods inherited from Base

#index_type, #soundex

Methods inherited from MethodBase

#index_name, #prepare_string, #stopwords, #with_context

Methods included from Redis

counter_key, #counter_key, #dictionary_key, #redis, #shared_key

Instance Method Details

#create_index(cntx) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fuzzzy/methods/soundex/indexer.rb', line 9

def create_index cntx
  with_context(cntx) do
    return if query_index_string.empty?

    delete_index
    redis.sadd(index_key(soundex), context[:id])
    save_dictionary(context[:id], query_index_string)
  end
end

#delete_index(cntx = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/fuzzzy/methods/soundex/indexer.rb', line 19

def delete_index cntx=nil
  block = lambda do
    if older_string = redis.get(dictionary_key(context[:id]))
      redis.srem(index_key(soundex(older_string)), context[:id])
      delete_dictionary(context[:id])
    end
  end
  cntx ? with_context(cntx, &block) : block.call
end

#query_index_stringObject



5
6
7
# File 'lib/fuzzzy/methods/soundex/indexer.rb', line 5

def query_index_string
  context[:prepared_dictionary_string] ||= prepare_string(context[:dictionary_string])
end