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.