Reputation: 11098
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? E.G. 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
Upvotes: 0
Views: 181
Reputation: 1877
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
Upvotes: 2