I have a Model with 2 atrributes:
:image_filename
:yt_video_id
I have this code in my controller:
def index
@search = Model.solr_search do |s|
s.fulltext params[:search]
s.paginate :page => params[:page], :per_page => 2
s.with(:image_filename || :yt_video_id)
end
@model = @search.results
respond_to do |format|
format.html # index.html.erb
end
end
in my model.rb Model I have this in searchable:
searchable do
string :image_filename, :yt_video_id
end
I want filter :image_filename OR :yt_video_id any are not "nil". I mean, both attributes must have a mandatory value.
but I get the error:
Sunspot::UnrecognizedFieldError in ModelsController#index
No field configured for Model with name 'image_filename'
The problem was fixed with the following steps:
(This solution works fine for me. I hope this solution can help you too.)
In model.rb you can not write this syntax:
You must write this syntax:
In your models_controller.rb in index action:
I have used the
any_ofmethod.To combine scopes using OR semantics, use the any_of method to group restrictions into a disjunction:
You can see in https://github.com/sunspot/sunspot/wiki/Scoping-by-attribute-fields