Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:52:42+00:00 2026-06-05T09:52:42+00:00

I have a Model with 2 atrributes: :image_filename :yt_video_id I have this code in

  • 0

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'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:52:44+00:00Added an answer on June 5, 2026 at 9:52 am

    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:

    searchable do
        string :image_filename, :yt_video_id
      end
    

    You must write this syntax:

    searchable do
          string :image_filename
          string :yt_video_id
         end
    

    In your models_controller.rb in index action:

    def index
       @search = Model.solr_search do |s|
       s.fulltext params[:search]
       s.paginate :page => params[:page], :per_page => 2
       s.any_of do
          without(:image_filename, nil)
          without(:yt_video_id, nil)
         end
       end
       @model = @search.results
       respond_to do |format|
        format.html # index.html.erb
       end
     end
    

    I have used the any_of method.

    To combine scopes using OR semantics, use the any_of method to group restrictions into a disjunction:

    Sunspot.search(Post) do
      any_of do
        with(:expired_at).greater_than(Time.now)
        with(:expired_at, nil)
      end
    end
    

    You can see in https://github.com/sunspot/sunspot/wiki/Scoping-by-attribute-fields

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Pin Model: class Pin < ActiveRecord::Base belongs_to :user belongs_to :image accepts_nested_attributes_for
I have this model which has Image field to be uploaded. It has a
Product controller: def update params[:product][:category_ids] ||= [] @product = Product.find(params[:id]) if @product.update_attributes(params[:product]) redirect_to @product
I'm following this rails cast to create a nested form: http://railscasts.com/episodes/196-nested-model-form-part-1 I have a
I have this string #<Fletcher::Model::Amazon alt=You Are Not a Gadget: A Manifesto (Vintage) border=0
I have a model, and when I do model.attributes.model I see the attributes of
I have a model with several attributes, among them title and artist . The
I have a model with nested attributes : class Foo < ActiveRecord::Base has_many :bar
I have authentication logic that uses cookies. The model attributes are initialized from cookies,
I want to have a Backbone model with float attributes in it but without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.