4
votes

I am using rails 4.0 with sunspot solr. I wish to do a this:

(read_flag IS TRUE) OR ( (read_flag IS NIL) AND (fulltext params[:search] is true))

This is my code in (post.rb):

@search =  Post.search do
  any_of
     with :model_id,params[:model_id]
     all_of
        with :model_id, nil
        fulltext params[:search] do
          fields(:title,:tags)
        end
     end
  end

end

However, the code above will generate this error undefined method 'fulltext' for #<Sunspot::DSL::Scope:0x007ff641ef2f38>

So I tried changing all_of to all. But it is not returning what I want.

The model file (post.rb) is indexed as per below

  searchable do
    integer :user_id
    text :title, :boost => 2
    integer :model_id
  end  

Can anyone advice on how should i structured my query? Couldn't find any relevant questions on stackoverflow.

1
any solution for this?Md. Farhan Memon

1 Answers

0
votes

I'm sure you have probably moved beyond this long ago, so for the benefit of anyone who might have found this question, I was struggling with a similar search using any_of and fulltext. I found ending the conjunction/disjunction before the fulltext seems to work:

@search =  Post.search do
  any_of
     with :model_id,params[:model_id]
     all_of
        with :model_id, nil
     end
  end
  fulltext params[:search] do
     fields(:title,:tags)
  end

end