module Redis::Search::ClassMethods
Public Instance Methods
prefix_match(q, opts = {})
click to toggle source
# File lib/redis-search/base.rb, line 146 def prefix_match(q, opts = {}) Redis::Search.complete(self.name, q, opts) end
redis_search(opts = {})
click to toggle source
Config
redis-search index for Model
Params:¶ ↑
title_field Query field for Search alias_field Alias field for search, can accept multi field (String or Array type) it type is String, redis-search will split by comma ext_fields What kind fields do you need inlucde to search indexes score_field Give a score for search sort, need Integer value, default is `created_at`
# File lib/redis-search/base.rb, line 120 def redis_search(opts = {}) opts[:title_field] ||= :title opts[:alias_field] ||= nil opts[:ext_fields] ||= [] opts[:score_field] ||= :created_at opts[:condition_fields] ||= [] opts[:class_name] ||= nil # Add score field to ext_fields opts[:ext_fields] += [opts[:score_field]] # Add condition fields to ext_fields opts[:ext_fields] += opts[:condition_fields] if opts[:condition_fields].is_a?(Array) # store Model name to indexed_models for Rake tasks Search.indexed_models = [] if Search.indexed_models.nil? Search.indexed_models << self class_variable_set('@@redis_search_options'.freeze, opts) end
redis_search_index(opts = {})
click to toggle source
# File lib/redis-search/base.rb, line 141 def redis_search_index(opts = {}) Kernel.warn 'DEPRECATION WARNING: redis_search_index is deprecated, use redis_search instead. ' redis_search(opts) end
redis_search_index_batch_create(batch_size = 1000)
click to toggle source
# File lib/redis-search/base.rb, line 150 def redis_search_index_batch_create(batch_size = 1000) count = 0 if ancestors.collect(&:to_s).include?('ActiveRecord::Base'.freeze) find_in_batches(batch_size: batch_size) do |items| _redis_search_reindex_items(items) count += items.count end elsif included_modules.collect(&:to_s).include?('Mongoid::Document'.freeze) self.all.each_slice(batch_size) do |items| _redis_search_reindex_items(items) count += items.count end else puts 'skiped, not support this ORM in current.' end count end
Private Instance Methods
_redis_search_reindex_items(items)
click to toggle source
# File lib/redis-search/base.rb, line 171 def _redis_search_reindex_items(items) items.each do |item| item.redis_search_index_create print DOT item = nil end items = nil end