Module: Litesearch

Included in:
Litedb
Defined in:
lib/litestack/litesearch.rb,
lib/litestack/litesearch.rb

Defined Under Namespace

Modules: Model Classes: Index, Schema, SchemaChangeException, SchemaException

Instance Method Summary collapse

Instance Method Details

#litesearch_index_cacheObject



11
12
13
# File 'lib/litestack/litesearch.rb', line 11

def litesearch_index_cache
  @litesearch_index_cache ||= {}
end

#search_index(name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/litestack/litesearch.rb', line 15

def search_index(name)
  # normalize the index name
  # find the index in the db cache
  name = name.to_s.downcase.to_sym
  index = litesearch_index_cache[name]
  # if the index is in the cache and no block is given then return it
  return index if index && !block_given?
  # if either there is no index in the cache or a block is given
  # create a new index instance and then place it in the cache and return
  index = if block_given?
    Index.new(self, name) do |schema|
      yield schema
      schema.name(name)
    end
  else
    Index.new(self, name)
  end
  litesearch_index_cache[name] = index
end