A few thoughts: * As you've noticed, Sphinx doesn't handle SQL queries for searches, and so ignores named_scopes. There are sphinx_scopes, though: http://freelancing-god.github.com/ts/en/scopes.html
* Make sure you're using attributes for ids and timestamps where you want sorting: has updated_at # instead of indexes updated_at, :sortable => true http://freelancing-god.github.com/ts/en/sphinx_basics.html * Mixing AND and ORs across what would probably be fields and attributes is complicated. Both multi-field searches and multiple filters on attributes are ANDs. It's possible to do the former with ORs if you manually construct your query string: Model.search "(@name,@location) Sydney", :match_mode => :extended But for ORs on filters, that's only really possible for multiple values on the one attribute: Model.search :with => {:attr_name => [1, 2, 3]} * If you're after something that specific, then it sounds like you're *finding* as opposed to *searching* - I know I'm getting a little pedantic on the terminology, but maybe Sphinx isn't the best tool for this query anyway. Sorry I can't figure out a solution for your exact problem - I'm pretty flat out with other projects at the moment. Good luck! Cheers -- Pat On 18/03/2010, at 4:42 AM, dnewman wrote: > I would like to run sphinx search against the results of a named scope > i have (see below). > > Seems like it will not work the way I had hoped (the search seems to > ignore the named_scope) and maybe I need to put everything in sphinx > instead of in AR. > > But how to convert this kind of query into sphinx ...boy am i lost on > that. I would love to get any idea or advice on how to proceed from > here. > > in model: > named_scope :user_in_and_following, lambda { |user| {:include => > [:user,:users], > :conditions => ["conversations.user_list like > '%,?,%' or (conversations.user_id in (?) and conversations.type = 3)", > user.id,user.following]} } > > define_index do > indexes body > indexes description > indexes title > indexes url > indexes tags.name, :as => :tag_name > indexes updated_at, :sortable => true > indexes comments.comment, :as => :comment_content > indexes [user.first_name, user.last_name], :as > => :user_name > end > > in controller: > @results = Conversation.search(params[:search], > :page => params[:page], :per_page => 25, :order => > "updated_at desc", > :field_weights => {:title => 20, > :tag => 17, > :url => 15, > :description => 14, > :body => 10, > :comment_content => 5}, > :match_mode => :boolean).compact > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/thinking-sphinx?hl=en. > -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
