Created
May 22, 2013 09:56
-
-
Save jumski/5626490 to your computer and use it in GitHub Desktop.
tire helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TireHelpers | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def drop_index | |
tire.index.delete | |
end | |
def create_index | |
tire.index.create mappings: tire.mapping_to_hash, | |
settings: tire.settings | |
end | |
def refresh_index | |
tire.index.refresh | |
end | |
def import_to_index | |
scope = if respond_to? :eager_loaded_associations | |
self.eager_loaded_associations | |
else | |
self.scoped | |
end | |
scope.count # hack to speed up | |
tire.index.import(scope.all) | |
end | |
def recreate_index | |
drop_index | |
create_index | |
import_to_index | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment