karmi/tire — Issue #137: Can not get type => 'geo_point' to work
Author: tcocca
Created: 2011-10-27 19:09:32+00:00
State: open

I am trying to set up my settings and mappings block to be able to create a geo_point.

I have the following set up in my model:

````
class Mls::Property
tire do
settings :analysis => {
:filter => {
:prefix_edgengram => {
"type" => "edgeNGram",
"min_gram" => 2,
"max_gram" => 10,
"side" => "front"
}
},
:analyzer => {
:prefix_analyzer => {
"tokenizer" => "lowercase",
"filter" => ["stop", "prefix_edgengram"],
"type" => "custom"
}
}
} do
mapping do
indexes :id, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :lat_lng, :type => 'geo_point', :lat_long => true
indexes :description, :type => 'string', :analyzer => 'snowball'
indexes :street_name, :type => 'string', :analyzer => 'prefix_edgengram'
indexes :building_style, :type => 'string', :analyzer => 'snowball'
indexes :list_office_name, :type => 'string', :analyzer => 'snowball'
indexes :sale_office_name, :type => 'string', :analyzer => 'snowball'
indexes :list_agent_name, :type => 'string', :analyzer => 'snowball'
indexes :sale_agent_name, :type => 'string', :analyzer => 'snowball'
indexes :state_abbreviation, :type => 'string', :index => "not_analyzed"
indexes :town_name, :type => 'string', :index => "not_analyzed"
indexes :neighborhood_name, :type => 'string', :index => "not_analyzed"
indexes :list_office_mls_id, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :sale_office_mls_id, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :list_agent_mls_id, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :sale_agent_mls_id, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :street_number, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :unit_number, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :zip, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :property_type_name, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :status_name, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :mls_id, :type => 'string', :index => "not_analyzed"
indexes :main_photo_url, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :virtual_tour_url, :type => 'string', :index => "not_analyzed", :include_in_all => false
indexes :service_id, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :state_id, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :town_id, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :neighborhood_id, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :property_type_id, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :status_id, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :bedrooms, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :full_bathrooms, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :half_bathrooms, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :quarter_bathrooms, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :three_quarter_bathrooms, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :total_bathrooms, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :price, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :sold_price, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :condo_fees, :type => 'double', :index => "not_analyzed", :include_in_all => false
indexes :square_footage, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :acres, :type => 'double', :index => "not_analyzed", :include_in_all => false
indexes :year_built, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :parking_spaces, :type => 'integer', :index => "not_analyzed", :include_in_all => false
indexes :taxes, :type => 'double', :index => "not_analyzed", :include_in_all => false
indexes :parking_available, :type => 'boolean', :null_value => false, :include_in_all => false
indexes :waterfront, :type => 'boolean', :null_value => false, :include_in_all => false
indexes :beachfront, :type => 'boolean', :null_value => false, :include_in_all => false
indexes :basement, :type => 'boolean', :null_value => false, :include_in_all => false
indexes :bank_owned, :type => 'boolean', :null_value => false, :include_in_all => false
indexes :opt_out, :type => 'boolean', :null_value => false, :include_in_all => false
indexes :sold, :type => 'boolean', :null_value => false, :include_in_all => false
indexes :sold_date, :type => 'date', :include_in_all => false
indexes :mls_created_at, :type => 'date', :include_in_all => false
indexes :mls_updated_at, :type => 'date', :include_in_all => false
indexes :open_house_dates, :type => 'date', :include_in_all => false
end
end
end

def to_indexed_json
{
:id => self.id,
:description => self.description,
:street_name => self.street_name,
:building_style => self.building_style,
:list_office_name => self.list_office.try(:name),
:sale_office_name => self.sale_office.try(:name),
:list_agent_name => self.list_agent.try(:name),
:sale_agent_name => self.sale_agent.try(:name),
:state_abbreviation => self.state.try(:abbreviation),
:town_name => self.town.try(:name),
:neighborhood_name => (!self.neighborhood_id.blank? && !self.neighborhood_id == 0 ? self.neighborhood.try(:name) : nil),
:list_office_mls_id => self.list_office.try(:mls_id),
:sale_office_mls_id => self.sale_office.try(:mls_id),
:list_agent_mls_id => self.list_agent.try(:mls_id),
:sale_agent_mls_id => self.sale_agent.try(:mls_id),
:street_number => self.street_number,
:unit_number => self.unit_number,
:zip => self.zip,
:property_type_name => self.property_type.try(:name),
:status_name => self.status.try(:name),
:mls_id => self.mls_id,
:main_photo_url => (picture_count > 0 && main_photo && !main_photo.url.blank? ? main_photo.url : nil),
:virtual_tour_url => (!virtual_tours.blank? ? virtual_tours.first.url : nil),
:service_id => self.service_id,
:state_id => self.state_id,
:town_id => self.town_id,
:neighborhood_id => self.neighborhood_id,
:property_type_id => self.property_type_id,
:status_id => self.status_id,
:bedrooms => self.bedrooms,
:full_bathrooms => self.full_bathrooms,
:half_bathrooms => self.half_bathrooms,
:quarter_bathrooms => self.quarter_bathrooms,
:three_quarter_bathrooms => self.three_quarter_bathrooms,
:total_bathrooms => self.total_baths,
:price => self.price,
:sold_price => self.sold_price,
:condo_fees => self.condo_fees,
:square_footage => self.square_footage,
:acres => self.acres,
:year_built => self.year_built,
:parking_spaces => self.parking_spaces,
:taxes => self.taxes,
:parking_available => self.parking_available?,
:waterfront => self.waterfront?,
:beachfront => self.beachfront?,
:basement => self.basement?,
:bank_owned => self.bank_owned?,
:opt_out => self.opt_out?,
:sold => self.sold?,
:sold_date => self.sold_date,
:mls_created_at => self.mls_created_at,
:mls_updated_at => self.mls_updated_at,
:open_house_dates => self.open_houses.collect{ |oh| oh.start_time },
:lat_lng => "#{self.latitude},#{self.longitude}"
}.to_json
end
````
And the first time I index a property:

p = Mls::Property.first
p.tire.update_index

It sets up my lat_lng property as a string.

I have tried the following formats in my :lat_lng => def in the json:

:lat_lng => "#{self.latitude},#{self.longitude}"

:lat_lng => [self.longitude, self.latitude]

:lat_lng => {
:lat => self.latitude},
:lon => self.longitude
}

All of which create the field as a string. Actually the last one created the field as a dynamic i think with lat and lon values of type string.

How can I go about getting my lat_lng point in as a geo_point ?

Also, how can I go about querying on geo_polygon

Thanks,
~ Tom