[英]How do I work with multiple params with thinking sphinx in ruby on rails
Let's say the following indexes my username and email colours of my users table so I can search by email addresses and usernames. 让我们说以下索引我的用户表的用户名和电子邮件颜色,以便我可以通过电子邮件地址和用户名进行搜索。
1) 1)
I would like to add 1 more thing and that is giving users the ability to also search by first and last name but I can't just add first_name and last_name to the define index method because these columns exist in the profiles table not the users. 我想再添加一件事,那就是让用户能够按名字和姓氏进行搜索,但我不能只将first_name和last_name添加到define index方法,因为这些列存在于profiles表而不是用户中。
How would I solve this issue? 我该如何解决这个问题? I would like to use the one text field to allow users to search username, email and first and last name.
我想使用一个文本字段来允许用户搜索用户名,电子邮件和名字和姓氏。
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) 2)
Also how can I get thinking sphinx to search using multiple options chosen by the user at once? 另外,如何使用用户一次选择的多个选项来思考sphinx? EG All users in united kingdom, who are between the age 20 and 30 (it would use the birthday column in the profiles table to work this out) etc. Basically I'd like to have a /browse page where users search by filtering... choosing many options and only having users returned to them that match these selections.
EG所有在英国的用户,年龄在20到30岁之间(它会使用个人资料表中的生日列来解决这个问题)等等。基本上我想要一个用户通过过滤搜索的/浏览页面。 ..选择许多选项,只让用户返回符合这些选项的选项。
Kind regards 亲切的问候
You can do it as follows: 你可以这样做:
define_index do
indexes profile.first_name, profile.last_name, :as => :full name
end
or 要么
define_index do
indexes profile.first_name
indexes profile.last_name
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.