Class: Fuzzzy::Ngram::Indexer
- Inherits:
-
Base
- Object
- MethodBase
- Base
- Fuzzzy::Ngram::Indexer
- Includes:
- Indexer
- Defined in:
- lib/fuzzzy/methods/ngram/indexer.rb
Constant Summary
Constants included from Redis
Instance Attribute Summary
Attributes inherited from MethodBase
Instance Method Summary collapse
Methods included from Indexer
#delete_dictionary, #save_dictionary
Methods inherited from Base
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 18 19 20 21 |
# File 'lib/fuzzzy/methods/ngram/indexer.rb', line 9 def create_index cntx with_context(cntx) do return if query_index_string.empty? delete_index ngrams.each_with_index do |ngram, index| redis.sadd(index_key(ngram, index), context[:id]) end save_dictionary(context[:id], query_index_string) end end |
#delete_index(cntx = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fuzzzy/methods/ngram/indexer.rb', line 23 def delete_index cntx=nil block = lambda do if older_string = redis.get(dictionary_key(context[:id])) ngrams(older_string).each_with_index do |ngram, index| redis.srem(index_key(ngram, index), context[:id]) end delete_dictionary(context[:id]) end end cntx ? with_context(cntx, &block) : block.call end |
#query_index_string ⇒ Object
5 6 7 |
# File 'lib/fuzzzy/methods/ngram/indexer.rb', line 5 def query_index_string context[:prepared_dictionary_string] ||= prepare_string(context[:dictionary_string]) end |