简体   繁体   中英

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)

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.

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)

Also how can I get thinking sphinx to search using multiple options chosen by the user at once? 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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