Skip to content
Snippets Groups Projects
Commit ba149bd4 authored by Constantine Mavromoustakos's avatar Constantine Mavromoustakos
Browse files

Added skip_index option to the geocoded_by and reverse_geocoded_by

methods to avoid creating an index by default.
parent 730e78ba
No related branches found
No related tags found
No related merge requests found
......@@ -83,6 +83,12 @@ Be sure to read <i>Latitude/Longitude Order</i> in the <i>Notes on MongoDB</i> s
MongoMapper is very similar to Mongoid, just be sure to include <tt>Geocoder::Model::MongoMapper</tt>.
=== MongoMapper, Mongoid Indexes
By default the methods geocoded_by and reverse_geocoded_by will create a geospatial index. If you want to skip this option call the methids with the :skip_index option
include Geocoder::Model::Mongoid
geocoded_by :address, :skip_index => true
=== Bulk Geocoding
If you have just added geocoding to an existing application with a lot of objects you can use this Rake task to geocode them all:
......
......@@ -16,7 +16,8 @@ module Geocoder
:geocode => true,
:user_address => address_attr,
:coordinates => options[:coordinates] || :coordinates,
:geocode_block => block
:geocode_block => block,
:skip_index => options[:skip_index] || false
)
end
......@@ -28,7 +29,8 @@ module Geocoder
:reverse_geocode => true,
:fetched_address => options[:address] || :address,
:coordinates => coordinates_attr,
:reverse_block => block
:reverse_block => block,
:skip_index => options[:skip_index] || false
)
end
......
......@@ -16,8 +16,10 @@ module Geocoder
def geocoder_init(options)
super(options)
ensure_index [[ geocoder_options[:coordinates], Mongo::GEO2D ]],
:min => -180, :max => 180 # create 2d index
if options[:skip_index] == false
ensure_index [[ geocoder_options[:coordinates], Mongo::GEO2D ]],
:min => -180, :max => 180 # create 2d index
end
end
end
end
......
......@@ -16,8 +16,10 @@ module Geocoder
def geocoder_init(options)
super(options)
index [[ geocoder_options[:coordinates], Mongo::GEO2D ]],
:min => -180, :max => 180 # create 2d index
if options[:skip_index] == false
index [[ geocoder_options[:coordinates], Mongo::GEO2D ]],
:min => -180, :max => 180 # create 2d index
end
end
end
end
......
......@@ -19,4 +19,9 @@ class MongoidTest < Test::Unit::TestCase
p = Place.near(location)
assert_equal p.selector[:location]['$nearSphere'], location.reverse
end
def test_index_is_skipped_if_skip_option_flag
result = PlaceWithoutIndex.index_options.keys.flatten[0] == :coordinates
assert_equal result, false
end
end
......@@ -29,3 +29,11 @@ class Place
write_attribute :address, address
end
end
class PlaceWithoutIndex
include Mongoid::Document
include Geocoder::Model::Mongoid
field :location, :type => Array
geocoded_by :location, :skip_index => true
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment