Module: Railstank::Search::ClassMethods

Defined in:
lib/railstank.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#index_nameObject

Returns the value of attribute index_name.



21
22
23
# File 'lib/railstank.rb', line 21

def index_name
  @index_name
end

#search_indexObject

Returns the value of attribute search_index.



21
22
23
# File 'lib/railstank.rb', line 21

def search_index
  @search_index
end

Instance Method Details

#has_indextank(class_index_name, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/railstank.rb', line 23

def has_indextank(class_index_name,options={})
  indextank_index_name = class_index_name.to_s
  
  define_method "index_name" do
    indextank_index_name
  end  
  define_method "search_index" do
    Railstank.client.indexes indextank_index_name
  end
  
  define_method "index_class_name" do
    options[:index_class_name].present? ? options[:index_class_name].to_s.underscore : self.class.name.underscore
  end
  
  @index_name = indextank_index_name
  @search_index = Railstank.client.indexes indextank_index_name
end

#isearch(field, options = {}) ⇒ Object



41
42
43
44
45
# File 'lib/railstank.rb', line 41

def isearch(field,options={})
  fetch_id_type = options[:fetch]
  results = search_index.search(field,options)["results"]
  result_ids = results.map{ |result| result[fetch_id_type] }.uniq
end