I am using ruby 1.9.3p392
rails 3.2.21
thinking sphinx 3.1.0
and Sphinx 2.2.4-id64-release
user_index.rb
file is :-
ThinkingSphinx::Index.define :user, :with => :active_record do
indexes first_name, :sortable => true
indexes last_name
indexes email
indexes user_name
indexes company_id
indexes id
indexes user_type_id
indexes department.name
indexes department.id, :as => :department_id
end
When i search as:-
assigned_user_ids = [372, 373, 374, 375, 367, 376, 377, 378, 379, 380]
@users = User.search(Riddle::Query.escape(params[:search]),
:conditions => {:company_id => @company.id},
:without => {:id => assigned_user_ids}, :per_page => PAGINATION_SIZE,
:page => params[:page])
But it is still showing the user
with id = 372
There are two issues here:
The first is that you're using fields instead of attributes for any non-string data, and that means some filters aren't going to work reliably. The second issue is that
id
is used by Sphinx internally, so you should either use Thinking Sphinx's automatic attributesphinx_internal_id
, or add an alias to your own attribute.So, I would recommend the following index definition instead:
And then your search would be:
In a completely unrelated note: unless this search is only being used by administrators, I would recommend you not have email addresses in your indexed data. Allowing people to search by email address is a security risk in most situations.