Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
rename "type" methods to "mapping"
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Sonnek committed Jan 23, 2012
1 parent 89f8909 commit d92fe10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions lib/elastic_searchable/index.rb
Expand Up @@ -3,28 +3,27 @@ module Indexing
module ClassMethods
# delete all documents of this type in the index
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/delete_mapping/
def clean_index
ElasticSearchable.request :delete, index_type_path
def delete_mapping
ElasticSearchable.request :delete, index_mapping_path
end

# configure the index for this type
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/put_mapping/
def update_index_mapping
if mapping = self.elastic_options[:mapping]
ElasticSearchable.request :put, index_type_path('_mapping'), :json_body => {index_type => mapping}
end
def create_mapping
return unless self.elastic_options[:mapping]
ElasticSearchable.request :put, index_mapping_path('_mapping'), :json_body => {index_type => mapping}
end

# delete one record from the index
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/delete/
def delete_id_from_index(id)
ElasticSearchable.request :delete, index_type_path(id)
ElasticSearchable.request :delete, index_mapping_path(id)
rescue ElasticSearchable::ElasticError => e
ElasticSearchable.logger.warn e
end

# helper method to generate elasticsearch url for this object type
def index_type_path(action = nil)
def index_mapping_path(action = nil)
ElasticSearchable.request_path [index_type, action].compact.join('/')
end

Expand All @@ -37,7 +36,7 @@ def index_type_path(action = nil)
#
# TODO: move this to AREL relation to remove the options scope param
def reindex(options = {})
self.update_index_mapping
self.create_mapping
options.reverse_merge! :page => 1, :per_page => 1000
scope = options.delete(:scope) || self
page = options[:page]
Expand Down Expand Up @@ -81,7 +80,7 @@ module InstanceMethods
def reindex(lifecycle = nil)
query = {}
query[:percolate] = "*" if _percolate_callbacks.any?
response = ElasticSearchable.request :put, self.class.index_type_path(self.id), :query => query, :json_body => self.as_json_for_index
response = ElasticSearchable.request :put, self.class.index_mapping_path(self.id), :query => query, :json_body => self.as_json_for_index

self.index_lifecycle = lifecycle ? lifecycle.to_sym : nil
_run_index_callbacks
Expand All @@ -108,7 +107,7 @@ def should_index?
def percolate(percolator_query = nil)
body = {:doc => self.as_json_for_index}
body[:query] = percolator_query if percolator_query
response = ElasticSearchable.request :get, self.class.index_type_path('_percolate'), :json_body => body
response = ElasticSearchable.request :get, self.class.index_mapping_path('_percolate'), :json_body => body
self.percolations = response['matches'] || []
self.percolations
end
Expand Down
2 changes: 1 addition & 1 deletion lib/elastic_searchable/queries.rb
Expand Up @@ -35,7 +35,7 @@ def search(query, options = {})
query[:sort] = sort
end

response = ElasticSearchable.request :get, index_type_path('_search'), :query => query, :json_body => options
response = ElasticSearchable.request :get, index_mapping_path('_search'), :query => query, :json_body => options
hits = response['hits']
ids = hits['hits'].collect {|h| h['_id'].to_i }
results = self.find(ids).sort_by {|result| ids.index(result.id) }
Expand Down

0 comments on commit d92fe10

Please sign in to comment.