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 7410483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:14:27+00:00 2026-05-29T06:14:27+00:00

I am currently building a Rails 3.2 application that uses the gem sunspot to

  • 0

I am currently building a Rails 3.2 application that uses the gem sunspot to provide search functionality for my application. sunspot uses Apache Solr to perform fulltext indexing and searching.

def index
    @search = Article.search do
      fulltext params[:search]
      with(:published_at).less_than(Time.zone.now)
      paginate :page => params[:page], :per_page => 10
      facet(:published_month)
    end
    @articles = @search.results

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @articles }
    end
end

Right now my code just performs a search every time someone hits the article index page and then renders the results. My concern is that solr goes down for some reason and my app dies with it. How could I implement a failsafe for this action that performs a basic Article.all whenever solr goes down?

I know that I could just rescue from the exception, but that would still mean that every request generates a connection attempt to solr. Is there a way to prevent this? (E.g. catching the exception once and then waiting 5 minutes before the app tries to reconnect to solr)

  • 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-29T06:14:27+00:00Added an answer on May 29, 2026 at 6:14 am

    As a contributor to Sunspot and the cofounder of Websolr, I recommend using rescue_from with a low-ish timeout.

    Where Sunspot is concerned, it looks like the option to specify a timeout was recently added to RSolr, the library Sunspot uses, so if this is a feature you need then you should look into contributing a pull request to Sunspot to pass a timeout to RSolr.

    Generating a failing request to Solr shouldn’t be that expensive if you have proper timeouts in place. If Solr is down, you want it to be timing out on opening the TCP connection. A healthy Solr server should open a TCP connection in an order of magnitude less than a second, and start sending data back in no more than a second or two for really expensive queries.

    An open timeout of 0.1 seconds and data timeout of 5 seconds should be more than enough here.

    The next best option here is to have some other local proxy between your application and Solr which can throttle requests when Solr is down. Perhaps a caching middleware, or Varnish. Certainly I’d see that as a more complicated approach, unless such a proxy or cache is already a part of your application’s infrastructure.

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

Sidebar

Related Questions

I'm building a Rails application that deals with file uploads through CarrierWave. Currently, larger
I'm currently building a rails application that contains 3 user types. This is my
I'm building a rails engine that uses the acts as format to establish relationships
Hi I'm currently building a little forum application with rails (3). I'm fairly new
Being quite new to rails and currently building a project, i'm begining to be
Currently building an app that runs on mobile phones not related to the issue
I am currently building my project locally using MVC. The user enters some search
I am currently building some application for iOS. It is actually my second application.
I'm currently building a desktop java application in a very clumsy manner. The application
I'm building a call-tracking application as a way to learn rails and twilio. Right

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.