如何使用思维 - 狮身人面像V3的方面

时间:2013-11-09 09:31:27

标签: ruby-on-rails-4 sphinx thinking-sphinx

使用V3,我无法显示方面:s:

我使用Rails 4.0.1,think-sphinx(3.0.6),最近在MacOS 10.9上使用'brew install sphinx --mysql'安装了sphinx

我用这种方式定义了我的索引:

ThinkingSphinx::Index.define :user, with: :active_record, delta: ThinkingSphinx::Deltas::DelayedDelta do

  #attributes
  has 'users.banned_at IS NULL and users.email_verified_at IS NOT NULL', as: :searchable, type: :boolean, facet: true
  has 'RADIANS(geo_latitude)', as: :latitude, type: :float
  has 'RADIANS(geo_longitude)', as: :longitude, type: :float

  has gender, facet: true
end

在我的控制器中:

@users = User.search with: {geodist: 0.0..100_000.0},
                         geo: [City.first.latitude, City.first.longitude]
@facets = @users.facets

然后在我看来(HAML语法)与V2相同的代码,它什么都没有渲染:

-@facets.each do |facet, facet_options|
  - %h5= facet
  -  %ul
    -facet_options.each do |option, count|
      -%li= link_to "#{option} (#{count})" (...)

@ facets.inspect给我这个:

  

     

{:geodist => 0.0..100000000.0},:geo => [46.15,4.91667],   :classes => [User(id:integer,gender:integer,name:string,   family_name:string,email:string,crypt_pass:string,salt:string,   auth_token:string,verif_token:string,password_reset_token:string,   password_reset_sent_at:datetime,city_id:integer,oauth_provider:   string,oauth_uid:integer,oauth_token:string,oauth_expires_at:   datetime,last_login_at:datetime,banned_at:boolean,created_at:   datetime,updated_at:datetime,schedule_mon_0:boolean,   schedule_mon_1:boolean,(...)schedule_available_holidays:boolean,   destroyed_email:string,destroyed_at:datetime,birthday:date,   mobility_km:integer,geo_search:string,geo_latitude:float,   geo_longitude:float,geo_streetnumber:string,geo_route:string,   geo_locality:string,geo_postal_code:string,   geo_administrative_area_level_2:string,   geo_administrative_area_level_1:string,geo_country:string,   geo_type:string,email_verified_at:datetime)]},@ query =“”,@ hash = {}>

我试图制作@facets.to_hash,但它给了我这个错误:

  

不推荐使用旧时尚@variables(@ count,@ weight等)

我遇到了这个问题,非常感谢你的帮助!

1 个答案:

答案 0 :(得分:2)

你很可能使用最近发布的Sphinx 2.1.2。 Sphinx的弃用想法有点奇怪(引发错误而不是警告),但TS v3.0.6能够切换到新语法。发行说明中涵盖了这一点:https://github.com/pat/thinking-sphinx/releases/tag/v3.0.6

如果您在进行了更改后仍然遇到问题,请告诉我们。