Skip to content
Snippets Groups Projects
Commit f723a647 authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge branch 'cm-add-skip-flag' of git://github.com/cmavromoustakos/geocoder...

Merge branch 'cm-add-skip-flag' of git://github.com/cmavromoustakos/geocoder into cmavromoustakos-cm-add-skip-flag

Conflicts:
	lib/geocoder/models/mongo_base.rb
	test/mongoid_test.rb
parents e860b4da ba149bd4
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:
......
......@@ -18,7 +18,8 @@ module Geocoder
:coordinates => options[:coordinates] || :coordinates,
:geocode_block => block,
:units => options[:units],
:method => options[:method]
:method => options[:method],
:skip_index => options[:skip_index] || false
)
end
......@@ -31,8 +32,9 @@ module Geocoder
:fetched_address => options[:address] || :address,
:coordinates => coordinates_attr,
:reverse_block => block,
:units => options[:units],
:method => options[:method]
:units => options[:units],
:method => options[:method],
: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
......
......@@ -30,4 +30,9 @@ class MongoidTest < Test::Unit::TestCase
Place.geocoded_by :address, :coordinates => :location, :units => :mi
assert_equal 69, p.distance_to([0,1]).round
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