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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:20:53+00:00 2026-05-17T02:20:53+00:00

I am implementing a full text search API for my rails apps, and so

  • 0

I am implementing a full text search API for my rails apps, and so far have been having great success with Thinking Sphinx.

I now want to implement a date range search, and keep getting the “bad value for range” error.

Here is a snippet of the controller code, and i’m a bit stuck on what to do next.

    @search_options = { :page => params[:page], :per_page => params[:per_page]||50 }

    unless params[:since].blank?
        # make sure date is in specified format - YYYY-MM-DD
        d = nil
        begin
            d = DateTime.strptime(params[:since], '%Y-%m-%d')
        rescue
            raise ArgumentError, "Value for since parameter is not a valid date - please use format YYYY-MM-DD"
        end
        @search_options.merge!(:with => {:post_date => d..Time.now.utc})
    end
    logger.info @search_options
    @posts = Post.search(params[:q], @search_options)

When I have a look at the log, I am seeing this bit which seems to imply the date hasn’t been converted into the same time format as the Time.now.utc.

withpost_date2010-05-25T00:00:00+00:00..Tue Jun 01 17:45:13 UTC 2010

Any ideas? Basically I am trying to have the API request pass in a “since” date to see all posts after a certain date. I am specifying that the date should be in the YYYY-MM-DD format.

Thanks for your help.
Chris

EDIT: I just changed the date parameters merge statement to this

@search_options.merge!(:with => {:post_date => d.to_date..DateTime.now})

and now I get this error

undefined method `to_i’ for Tue, 25 May 2010:Date

So obviously there is something still not setup right…

  • 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-17T02:20:54+00:00Added an answer on May 17, 2026 at 2:20 am

    I finally solved this, but it takes a slightly different approach but it works fine.

    I was trying to put the date-range search inside a sphinx_scope (in the model) or as a :condition or :with (in the controller). This did not work, so instead I had to implement it inside the define_index in the model.

    So what I did was put a check in the define_index to see if a record fell within a date range, the date range being defined by some SQL code, as shown below. In this case, I wanted to see if “start_date” fell within a date between now and 30 days ago, and an “end_date” fell within today and 30 days from now.

    If the dates fell within the ranges, the code below causes the :live to be 0 or 1, depending on whether it falls outside or inside the date ranges (respectively):

    define index do
        # fields:
        ...
        # attributes:
        has "CASE WHEN start_date > DATE_ADD(NOW(), INTERVAL -30 DAY) AND end_date < DATE_ADD(NOW(), INTERVAL 30 DAY) THEN 1 ELSE 0 END", :type => :integer, :as => :live
        ...
        # delta:
        ...
    end

    Then in your controller, all you have to do is check if :live => 1 to obtain all records that have start_dates and end_dates within the date ranges.

    I used a sphinx_scope like this:

    sphinx_scope(:live) {
        { :with => { :live => 1 } }
    }

    and then in my controller:

    @models = Model.live.search(...)

    To make sure it works well, you of course need to implement frequent reindexing to make sure the index is up to date, i.e. the correct records are :live => 1 or 0!

    Anyway, this is probably a bit late for you now, but I implemented it and it works like a charm!!!

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

Sidebar

Related Questions

I'm implementing full text search functionality on my rap website , and I'm running
I'm looking into implementing full text search on our Firebird database. Our requirements are:
I'm working with SQL trying to implement a Full-Text-Search. I noticed that there is
I am building a full text search facility for my website coded in asp.net
I have a rails app in which I am trying to do some full
I have been implementing an LLRB package that should be able to operate in
I have a problem implementing an API that works with Java, but fails to
I'm currently working on implementing a fulltext search engine for one of our sites,
implementing publishActivity in PHP using the REST API using this code: $activity = array(
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written

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.