【问题标题】:How to use facets with thinking-sphinx V3如何在thinking-sphinx V3中使用构面
【发布时间】:2013-11-09 09:31:26
【问题描述】:

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

我使用 Rails 4.0.1、thinking-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=>[用户(id:整数,性别:整数,名称:字符串, family_name:字符串,电子邮件:字符串,crypt_pass:字符串,盐:字符串, auth_token:字符串,verif_token:字符串,password_reset_token:字符串, password_reset_sent_at:日期时间,city_id:整数,oauth_provider: 字符串,oauth_uid:整数,oauth_token:字符串,oauth_expires_at: 日期时间,last_login_at:日期时间,banned_at:布尔值,created_at: 日期时间,updated_at:日期时间,schedule_mon_0:布尔值, schedule_mon_1:布尔值,(...) schedule_available_holidays:布尔值, destroy_email:字符串,destroy_at:日期时间,生日:日期, 移动公里:整数,地理搜索:字符串,地理纬度:浮动, geo_longitude:浮动,geo_streetnumber:字符串,geo_route:字符串, geo_locality:字符串,geo_postal_code:字符串, geo_administrative_area_level_2:字符串, geo_administrative_area_level_1:字符串,geo_country:字符串, geo_type: string, email_verified_at: datetime)]}, @query="", @hash={}>

我尝试创建@facets.to_hash,但它给了我这个错误:

不推荐使用老式的@variables(@count、@weight 等)

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

【问题讨论】:

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


    【解决方案1】:

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

    如果您在进行此处所述的更改后仍有问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多