Sphinx: change column set for searching in runtime

Posted by Fedyashev Nikita on Stack Overflow See other posts from Stack Overflow or by Fedyashev Nikita
Published on 2010-05-15T04:04:12Z Indexed on 2010/05/15 4:14 UTC
Read the original article Hit count: 217

Filed under:
|
|

I use Ultrasphinx gem plugin as a wrapper for accessing Sphinx search daemon.

My model declaration:

class Foo < ActiveRecord::Base
  is_indexed :fields => ['content', 'private_notes', 'user_id']

Client code:

 filters = {}
 if type == "private"
   # search only in `content` column
   filters['user_id'] = current_user.id
 else
   # search in `content` and `private_notes` columns
 end

 results = Ultrasphinx::Search.new(:query => params[:query],
                                   :per_page => 20,
                                   :page => params[:page] || 1,
                                   :filters => filters)

The problem I have now with Ultrasphinx gem(or Sphinx, in general?) is that it does not allow me to change set of fields where to look for matches IN RUNTIME

How can I solve this problem?

© Stack Overflow or respective owner

Related posts about sphinx

Related posts about ruby-on-rails