class Deal < ActiveRecord::Base

  belongs_to :buyer
 define_index do

    indexes buyer.name,  :as   => :buyer_name
    indexes buyer.zip_code.city_name => :city_name
  end
end

class Buyer < ActiveRecord::Base
  belongs_to  :zip_code


  define_index do
      indexes :name, :as => :name, :sortable => true
      indexes :created_at, :sortable => true
      has partner_id, :as => :partner_id
      set_property  :delta => true
    end
end

class ZipCode < ActiveRecord::Base
define_index do
    indexes :country

    has 'RADIANS(latitude)',  :as => :latitude,     :type => :float
    has 'RADIANS(longitude)', :as => :longitude,    :type => :float

    has searchable_by_area_code
    set_property :latitude_attr   => "latitude"
    set_property :longitude_attr  => "longitude"
  end
end

generated sql query for index:
 sql_query = SELECT `deals`.`id` * 8 + 4 AS `id` ,
CAST(`buyers`.`name` AS CHAR) AS `buyer_name`,
CAST(`deals`.`city_name` AS CHAR) AS `city_name`, `deals`.`id` AS
`sphinx_internal_id`, 1137471016 AS `class_crc`, '1137471016' AS
`subclass_crcs`, 0 AS `sphinx_deleted` FROM `deals`    LEFT OUTER JOIN
`buyers` ON `buyers`.id = `deals`.buyer_id  WHERE `deals`.`id` >=
$start AND `deals`.`id` <= $end GROUP BY `deals`.`id`  ORDER BY NULL
  sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1)
FROM `deals`

as you can see it's doing deals.city_name instead of
zip_codes.city_name and is not joining zip_codes at all.

I use zip_codes successfully to do geo location on tables that have a
zip_code_id in their table.

Are the indexes in the zip_code model interfering somehow with the
deal model?

indexes on the buyers.name works fine.  Also, i have other indexes
like this:
#indexes trims.model.make.name,    :as   => :make_name

in the deal.rb file that also have worked fine.  ts created the joins
that were needed and did the select like makes.name which is correct.
it didn't do something like deals.name or anything like it is doing
for the two belongs_to associations.  Any help would be great,
thanks.

Erik

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to