class RediSearch::Index
Attributes
model[R]
name[R]
schema[R]
Public Class Methods
new(name, schema, model = nil)
click to toggle source
# File lib/redi_search/index.rb, line 14 def initialize(name, schema, model = nil) @name = name.to_s @schema = Schema.new(schema) @model = model end
Public Instance Methods
add(document)
click to toggle source
# File lib/redi_search/index.rb, line 48 def add(document) Hset.new(self, document).call end
add!(document)
click to toggle source
# File lib/redi_search/index.rb, line 52 def add!(document) Hset.new(self, document).call! end
add_field(field_name, schema)
click to toggle source
# File lib/redi_search/index.rb, line 97 def add_field(field_name, schema) AddField.new(self, field_name, schema).call! end
add_multiple(documents)
click to toggle source
# File lib/redi_search/index.rb, line 56 def add_multiple(documents) client.multi do documents.each do |document| add(document) end end.all? { |response| response >= 0 } end
create(**options)
click to toggle source
# File lib/redi_search/index.rb, line 28 def create(**options) Create.new(self, schema, options).call end
create!(**options)
click to toggle source
# File lib/redi_search/index.rb, line 32 def create!(**options) Create.new(self, schema, options).call! end
del(document)
click to toggle source
# File lib/redi_search/index.rb, line 64 def del(document) document.del end
document_count()
click to toggle source
# File lib/redi_search/index.rb, line 93 def document_count info.num_docs.to_i end
drop(keep_docs: false)
click to toggle source
# File lib/redi_search/index.rb, line 36 def drop(keep_docs: false) drop!(keep_docs: keep_docs) rescue Redis::CommandError false end
drop!(keep_docs: false)
click to toggle source
# File lib/redi_search/index.rb, line 42 def drop!(keep_docs: false) command = ["DROPINDEX", name] command << "DD" unless keep_docs client.call!(*command.compact).ok? end
exist?()
click to toggle source
# File lib/redi_search/index.rb, line 68 def exist? !client.call!("INFO", name).empty? rescue Redis::CommandError false end
fields()
click to toggle source
# File lib/redi_search/index.rb, line 82 def fields schema.fields.map { |field| field.name.to_s } end
info()
click to toggle source
# File lib/redi_search/index.rb, line 74 def info hash = Hash[*client.call!("INFO", name)] info_struct = Struct.new(*hash.keys.map(&:to_sym)) info_struct.new(*hash.values) rescue Redis::CommandError nil end
reindex(documents, recreate: false)
click to toggle source
# File lib/redi_search/index.rb, line 86 def reindex(documents, recreate: false) drop if recreate create unless exist? add_multiple documents end
search(term = nil, **term_options)
click to toggle source
# File lib/redi_search/index.rb, line 20 def search(term = nil, **term_options) Search.new(self, term, **term_options) end
spellcheck(query, distance: 1)
click to toggle source
# File lib/redi_search/index.rb, line 24 def spellcheck(query, distance: 1) Spellcheck.new(self, query, distance: distance) end
Private Instance Methods
client()
click to toggle source
# File lib/redi_search/index.rb, line 103 def client RediSearch.client end