如何使用ThinkingSphinx对多款车型进行地理搜索? [英] How do I geo-search multiple models with ThinkingSphinx?

查看:0
本文介绍了如何使用ThinkingSphinx对多款车型进行地理搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个用于搜索的模型索引(用户和项目)。我正试着在不同的模特之间进行地理搜索:

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

推荐答案

这是一个较晚的响应,但总比没有好,希望:

当您不是在特定模型上搜索时,认为Sphinx没有了解哪些属性可用的参考点,因此您需要显式地告诉它要使用的LATE和LONG属性:

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"
)

这篇关于如何使用ThinkingSphinx对多款车型进行地理搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆