Module: Redis::Search::ClassMethods
- Defined in:
- lib/redis/search/base.rb
Instance Method Summary collapse
-
#redis_search_index(opts = {}) ⇒ Object
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 prefix_index_enable Is use prefix index search 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`.
- #redis_search_index_batch_create(batch_size = 1000, progressbar = false) ⇒ Object
Instance Method Details
#redis_search_index(opts = {}) ⇒ Object
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
prefix_index_enable Is use prefix index search
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`
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/redis/search/base.rb', line 121 def redis_search_index(opts = {}) opts[:title_field] ||= :title opts[:alias_field] ||= nil opts[:prefix_index_enable] ||= false 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_batch_create(batch_size = 1000, progressbar = false) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/redis/search/base.rb', line 143 def redis_search_index_batch_create(batch_size = 1000, = false) count = 0 if self.ancestors.collect { |klass| klass.to_s }.include?("ActiveRecord::Base".freeze) find_in_batches(:batch_size => batch_size) do |items| items.each do |item| item.redis_search_index_create count += 1 print "." if end end elsif self.included_modules.collect { |m| m.to_s }.include?("Mongoid::Document".freeze) all.each_slice(batch_size) do |items| items.each do |item| item.redis_search_index_create count += 1 print "." if end end else puts "skiped, not support this ORM in current." end count end |