简体   繁体   English

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

[英]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.

相关问题 如何使用Ruby on Rails在Windows 7上安装Thinking Sphinx? - How do I Install Thinking Sphinx on windows 7 with Ruby on Rails? 在Ruby on Rails中使用多个模型使用Thinking Sphinx的问题 - Problems using Thinking Sphinx in Ruby on Rails with multiple models 当思想狮身人面像找到数据时,您如何将数据从Rails中的ruby中的哈希中提取出来? - When thinking-sphinx finds data how do you then pull data out of the hash in ruby on rails? 思维狮身人面像Rails多重关联 - Thinking Sphinx Rails Multiple Association Rails和thinking_sphinx什么时候我应该做reindex? - Rails and thinking_sphinx when I should do reindex? Rails:将cumming_sphinx与Cucumber和Webrat进行集成测试-如何索引事务性固定装置? - Rails: Integration testing thinking_sphinx with cucumber and webrat - how do I index transactional fixtures? 如何在无循环依赖的情况下使用Think Sphinx在Rails 5中索引多态(STI)模型? - How do I index polymorphic (STI) models in Rails 5 with Thinking Sphinx without a circular dependency? 如何在思考狮身人面像导轨中进行多方面搜索 - How to do multi facets search in thinking sphinx rails 你如何在Rails 3上使用Thinking Sphinx排序? - How do you sort Using Thinking Sphinx on Rails 3? Ruby on Rails,狮身人面像。 错误:不知道如何构建任务“ thinking_sphinx:index” - Ruby on rails, Sphinx. error : Don't know how to build task 'thinking_sphinx:index'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM