Module: Spinel::Searcher
- Included in:
- Client
- Defined in:
- lib/spinel/searcher.rb
Instance Method Summary collapse
- #cache_enable(key) ⇒ Object
- #search(term, options = {}) ⇒ Object
- #search_option(options = {}) ⇒ Object
- #search_word_split(word) ⇒ Object
- #set_cache(key, words) ⇒ Object
Instance Method Details
#cache_enable(key) ⇒ Object
31 32 33 |
# File 'lib/spinel/searcher.rb', line 31 def cache_enable key Spinel.redis.exists(key) end |
#search(term, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/spinel/searcher.rb', line 4 def search term, = {} = search_option words = search_word_split term return [] if words.empty? tmp_cachekey = cachekey(words) set_cache(tmp_cachekey, words) unless [:cache] && cache_enable(tmp_cachekey) ids = Spinel.redis.zrevrange(tmp_cachekey, 0, [:limit] - 1) ids.empty? ? [] : Spinel.redis.hmget(database, *ids).compact.map{|json| MultiJson.decode(json)} end |
#search_option(options = {}) ⇒ Object
17 18 19 |
# File 'lib/spinel/searcher.rb', line 17 def search_option = {} { limit: Spinel.search_limit, cache: true }.merge() end |
#search_word_split(word) ⇒ Object
21 22 23 |
# File 'lib/spinel/searcher.rb', line 21 def search_word_split word squish(word).split.reject{|w| w.size < Spinel.minimal_word}.sort end |