1

検索用にインデックス付けされた2つのモデル(ユーザーとアイテム)があります。モデル間で地理検索を実行しようとしています。

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

しかし、エラーが発生するだけです。

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

各モデルを個別に検索することは問題なく機能します...しかし、ここでの問題が何であるかはわかりません。インデックスは次のとおりです。

ユーザーインデックス:

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    

アイテムインデックス:

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
4

1 に答える 1

3

これは遅い応答ですが、うまくいけば、何もないよりはましです:

特定のモデルを検索していない場合、Thinking Sphinx には使用可能な属性を知るための参照ポイントがないため、使用する緯度と経度の属性を明示的に指定する必要があります。

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"
)
于 2009-01-21T12:17:07.150 に答える