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

  • Home
  • SEARCH
  • 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 7009195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:49:54+00:00 2026-05-27T21:49:54+00:00

I was writing a Blog like application Using Rails3/Mongoid, and now trying to use

  • 0

I was writing a Blog like application Using Rails3/Mongoid, and now trying to use Sunspot for full-text search

I follow these steps: https://github.com/outoftime/sunspot , install this https://github.com/jugyo/sunspot_mongoid as plugin, and add the following code to make the sunspot:reindex work correctly,

module Mongoid
  module BaseModel
    extend ActiveSupport::Concern

    included do
      scope :recent, desc(:_id)
      scope :exclude_ids, Proc.new { |ids| where(:_id.nin => ids.map(&:to_i)) }
    end

    module ClassMethods
      # like ActiveRecord find_by_id
      #def find_by_id(id)
      #  if id.is_a?(Integer) or id.is_a?(String)
      #    where(:_id => id.to_i).first
      #  else
      #    nil
      #  end
      #end

      def find_in_batches(opts = {})
        batch_size = opts[:batch_size] || 1000
        start = opts.delete(:start).to_i || 0
        objects = self.limit(batch_size).skip(start)
        t = Time.new
        while objects.any?
          yield objects
          start += batch_size
          # Rails.logger.debug("processed #{start} records in #{Time.new - t} seconds") if Rails.logger.debug?
          break if objects.size < batch_size
          objects = self.limit(batch_size).skip(start)
        end
      end
    end
  end
end

and in my post model :

  include Sunspot::Mongoid
  searchable do
    text :title, :stored => true
    text :content, :stored => true
    text :comments, :stored => true do
      comments.map { |comment| comment.content }
    end                                                                                                  
    time :last_comment_at
  end 

but when i use @search = Post.search it always give me this error ..

Mongoid::Errors::InvalidFind in SearchController#index
Calling Document#find with nil is invalid

I find it may be conflict to Mongoid or something,and change it to Post.solr_search

but it still can’t work :

[parano@u330 attix.us]$ bundle exec rake sunspot:solr:start 
:public is no longer used to avoid overloading Module#public, use :public_folder instead
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/resque-1.19.0/lib/resque/server.rb:12:in `<class:Server>'
Removing stale PID file at /home/parano/code/rails_projects/attix.us/solr/pids/development/sunspot-solr-development.pid
Successfully started Solr ...


[parano@u330 attix.us]$ rails console
:public is no longer used to avoid overloading Module#public, use :public_folder instead
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/resque-1.19.0/lib/resque/server.rb:12:in `<class:Server>'
Loading development environment (Rails 3.1.3)

ruby-1.9.3-p0 :001 > p = Post.solr_search { fulltext 'vero' }

 => <Sunspot::Search:{:fq=>["type:Post"], :q=>"vero", :fl=>"* score", :qf=>"title_texts content_texts comments_texts", :defType=>"dismax", :start=>0, :rows=>30}> 

ruby-1.9.3-p0 :002 > p.results

NoMethodError: undefined method `id' for #<Array:0xb4916b8>
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/mongoid-2.3.4/lib/mongoid/criteria.rb:382:in `method_missing'
    from /home/parano/code/rails_projects/attix.us/vendor/plugins/sunspot_mongoid/lib/sunspot/mongoid.rb:45:in `criteria'
    from /home/parano/code/rails_projects/attix.us/vendor/plugins/sunspot_mongoid/lib/sunspot/mongoid.rb:39:in `load_all'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/sunspot-1.3.0/lib/sunspot/search/abstract_search.rb:228:in `block in populate_hits'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/sunspot-1.3.0/lib/sunspot/search/abstract_search.rb:224:in `each_pair'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/sunspot-1.3.0/lib/sunspot/search/abstract_search.rb:224:in `populate_hits'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/sunspot-1.3.0/lib/sunspot/search/hit.rb:90:in `result'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/sunspot-1.3.0/lib/sunspot/search/abstract_search.rb:275:in `block in verified_hits'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/sunspot-1.3.0/lib/sunspot/search/paginated_collection.rb:50:in `select'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/sunspot-1.3.0/lib/sunspot/search/paginated_collection.rb:50:in `method_missing'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/sunspot-1.3.0/lib/sunspot/search/abstract_search.rb:275:in `verified_hits'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/sunspot-1.3.0/lib/sunspot/search/abstract_search.rb:59:in `results'
    from (irb):2
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
    from /home/parano/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'ruby-1.9.3-p0 :003 > 

anyone can help me ?

  • 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-05-27T21:49:55+00:00Added an answer on May 27, 2026 at 9:49 pm

    This is very beta. I tried to make the simplest example work with sunspot_mongoid and had no luck. No rake tasks included, might be related to this issue on github:

    https://github.com/jugyo/sunspot_mongoid/issues/7

    Maybe if you file an issue over there the maintainer will be able to take a look and respond.

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

Sidebar

Related Questions

I'm writing a simple blog-like application for Django and am trying to get the
I'm writing a custom blog engine and would like to have trackbacks similar to
I've followed this tutorial: http://anandhansubbiah.com/blog/writing-your-first-android-application/ , but no matter what I do, and what
I have been writing articles on the wordpress.com blog , now I am looking
I am trying to finish writting my news/blog ASP.net C# application and I am
I have followed a tutorial to create a simple blog writing application in PHP
I'm writing a blog on Java, now I have have 2 servlets models, in
I'm a Java geek and I've started writing a blog (using Wordpress), but blog
I'm writing a very simple blog engine for own use (since every blog engine
In development I used sqlite3 and I was writing a blog application. So for

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.