Skip to content

Instantly share code, notes, and snippets.

@jumski
Created May 22, 2013 09:56
Show Gist options
  • Save jumski/5626490 to your computer and use it in GitHub Desktop.
Save jumski/5626490 to your computer and use it in GitHub Desktop.
tire helpers
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