首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用ThinkingSphinx对多个型号进行地理搜索?

如何使用ThinkingSphinx对多个型号进行地理搜索?
EN

Stack Overflow用户
提问于 2008-11-05 18:00:49
回答 1查看 1.4K关注 0票数 1

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

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 ''

单独搜索每个模型都很好……但我不知道这里的问题是什么。以下是索引:

用户索引:

代码语言:javascript
复制
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    

项目索引:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-01-21 12:17:07

这是一个迟来的回应,但希望总比什么都没有好:

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

代码语言:javascript
复制
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"
)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/266048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档