Skip to content

Commit

Permalink
Option to disable indexing if required.
Browse files Browse the repository at this point in the history
  • Loading branch information
dougal committed Mar 7, 2011
1 parent 1c0199a commit 8ef16b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/acts_as_indexed/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def acts_as_indexed(options = {})
# Adds the passed +record+ to the index. Index is built if it does not already exist. Clears the query cache.

def index_add(record)
return if self.aai_config.disable_indexing

build_index unless aai_config.index_file.directory?
index = new_index
index.add_record(record)
Expand All @@ -67,6 +69,8 @@ def index_add(record)
# Removes the passed +record+ from the index. Clears the query cache.

def index_remove(record)
return if self.aai_config.disable_indexing

index = new_index
index.remove_record(record)
@query_cache = {}
Expand All @@ -77,6 +81,8 @@ def index_remove(record)
# 2. Adds the new version to the index.

def index_update(record)
return if self.aai_config.disable_indexing

build_index unless aai_config.index_file.directory?
index = new_index
index.update_record(record,find(record.id))
Expand Down Expand Up @@ -115,7 +121,7 @@ def search_index(query, find_options={}, options={})
if find_option_keys.any?
raise ArgumentError, 'ids_only can not be combined with find option keys other than :offset or :limit'
end
end
end

if find_options.include?(:order)
part_query = @query_cache[query].map{ |r| r.first }
Expand Down
6 changes: 6 additions & 0 deletions lib/acts_as_indexed/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ class Configuration
# Set to true to enable.
# Default is false.
attr_accessor :case_sensitive

# Disable indexing, useful for large test suites.
# Set to false to disable.
# Default is false.
attr_accessor :disable_indexing

def initialize
@index_file = nil
@index_file_depth = 3
@min_word_size = 3
@if_proc = if_proc
@case_sensitive = false
@disable_indexing = false
end

# Since we cannot expect Rails to be available on load, it is best to put
Expand Down

0 comments on commit 8ef16b7

Please sign in to comment.