【问题标题】:How do I work with multiple params with thinking sphinx in ruby on rails如何在 ruby​​ on rails 中使用多个参数来思考 sphinx
【发布时间】:2012-01-27 11:02:27
【问题描述】:

假设以下索引我的用户名和用户表的电子邮件颜色,以便我可以按电子邮件地址和用户名进行搜索。

1)

我想再添加 1 件事,即让用户也能够按名字和姓氏搜索,但我不能只将 first_name 和 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)

另外,我怎样才能让思考狮身人面像一次使用用户选择的多个选项进行搜索?例如。英国的所有用户,年龄在 20 到 30 岁之间(它会使用配置文件表中的生日列来解决这个问题)等。基本上我想要一个 /browse 页面,用户通过过滤进行搜索.. . 选择许多选项,并且只让用户返回与这些选项匹配的用户。

亲切的问候

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1 rubygems


    【解决方案1】:

    你可以这样做:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多