繁体   English   中英

如何在轨道上用红宝石思考狮身人面像时使用多个参数

[英]How do I work with multiple params with thinking sphinx in ruby on rails

让我们说以下索引我的用户表的用户名和电子邮件颜色,以便我可以通过电子邮件地址和用户名进行搜索。

1)

我想再添加一件事,那就是让用户能够按名字和姓氏进行搜索,但我不能只将first_name和last_name添加到define index方法,因为这些列存在于profiles表而不是用户中。

我该如何解决这个问题? 我想使用一个文本字段来允许用户搜索用户名,电子邮件和名字和姓氏。

class User < ActiveRecord::Base

  has_one :profile, :autosave => true
  has_many :photo_albums
  accepts_nested_attributes_for :profile, :photo_albums

  # thinking sphinx
  define_index do
    indexes username
    indexes email
  end

2)

另外,如何使用用户一次选择的多个选项来思考sphinx? EG所有在英国的用户,年龄在20到30岁之间(它会使用个人资料表中的生日列来解决这个问题)等等。基本上我想要一个用户通过过滤搜索的/浏览页面。 ..选择许多选项,只让用户返回符合这些选项的选项。

亲切的问候

你可以这样做:

define_index do
  indexes profile.first_name, profile.last_name, :as => :full name
end

要么

define_index do
  indexes profile.first_name
  indexes profile.last_name
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM