views:

615

answers:

1

Hello,

I have two models indexed for searching (User and Item). I'm trying to do a geo-search across models:

ThinkingSphinx::Search.search('keywords', :geo => [ degrees_to_radians(params[:lat].to_f), degrees_to_radians(params[:lon].to_f) ], )

But I only get an error:

Sphinx Error: index item_core,item_delta,user_core,user_delta: unknown latitude attribute ''

Searching each model individually works fine... but I've no idea what the problem here is. Here are the indexes:

User Index:

define_index do
    indexes [:first_name, :last_name], :as => :name
    indexes login
    indexes email
    indexes headline
    indexes description
    indexes business.name, :as => :business_name
    indexes [addresses.street_1, addresses.street_2, addresses.city, addresses.postal_code], :as => :address

    has created_at, :sortable => true
    has addresses.latitude, :as => :latitude, :type => :float
    has addresses.longitude, :as => :longitude, :type => :float    

    set_property :delta => true
  end

Item index:

define_index do
    indexes title, :sortable => true
    indexes description
    indexes [address.street_1, address.street_2, address.city, address.postal_code], :as => :address
    indexes images.title, :as => :image_titles
    indexes images.description, :as => :image_descriptions
    indexes categories(:name), :as => :category_names    

    has price, :sortable => true
    has created_at, :sortable => true
    has address.latitude, :as => :latitude, :type => :float
    has address.longitude, :as => :longitude, :type => :float    
    has categories(:id), :as => :category_ids

    where "`items`.`state` = 'for_sale'"

    set_property :delta => true    
  end
+1  A: 

This is a late response, but better than nothing, hopefully:

When you're not searching on a specific model, Thinking Sphinx has no reference point for knowing what attributes are available, so you need to explicitly tell it the lat and long attributes to use:

ThinkingSphinx::Search.search('keywords',
  :geo => [
    degrees_to_radians(params[:lat].to_f),
    degrees_to_radians(params[:lon].to_f)
  ],
  :latitude_attr  => "latitude",
  :longitude_attr => "longitude"
)
pat