Module: Slingshot::Model::Indexing::ClassMethods

Defined in:
lib/slingshot/model/indexing.rb

Instance Method Summary collapse

Instance Method Details

#create_index_or_update_mappingObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/slingshot/model/indexing.rb', line 28

def create_index_or_update_mapping
  # STDERR.puts "Creating index with mapping", mapping_to_hash.inspect
  # STDERR.puts "Index exists?, #{index.exists?}"
  unless index.exists?
    index.create :mappings => mapping_to_hash
  else
    # TODO: Update mapping
  end
rescue Exception => e
  # TODO: STDERR + logger
  raise
end

#indexes(name, options = {}) ⇒ Object



19
20
21
22
# File 'lib/slingshot/model/indexing.rb', line 19

def indexes(name, options = {})
  # p "#{self}, SEARCH PROPERTY, #{name}"
  mapping[name] = options
end

#mappingObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/slingshot/model/indexing.rb', line 8

def mapping
  if block_given?
    @store_mapping = true
    yield
    @store_mapping = false
    create_index_or_update_mapping
  else
    @mapping ||= {}
  end
end

#mapping_to_hashObject



41
42
43
# File 'lib/slingshot/model/indexing.rb', line 41

def mapping_to_hash
  { document_type.to_sym => { :properties => mapping } }
end

#store_mapping?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/slingshot/model/indexing.rb', line 24

def store_mapping?
  @store_mapping || false
end