Gmail Calendar Documents Web Reader more
foley.sj@gmail.com | My Groups | Favorites | Profile | Help | My Account | Sign out
Google Groups Home
Searching for Dates
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Expand all  -  Translate all to Translated (View all originals)  - 
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Finding_Zion  
View profile  
 More options Jan 20 2009, 2:28 pm
From: Finding_Zion <jeremy.g.peter...@gmail.com>
Date: Tue, 20 Jan 2009 10:28:06 -0800 (PST)
Local: Tues, Jan 20 2009 2:28 pm
Subject: Searching for Dates
I need to add a range search for dates.  The usage guide mentions that
dates are converted to timestamps, however it would be nice to have
some examples for how to search them.  This is what I have so far and
it isn't search the way I'd expect.

In the model:
  indexes data.pub_date, :as => :pub_date

Phase 1 (Search for a date field)
When searching, I add the following condition.
  :conditions => {:pub_date => "8/31/2008".to_time.to_i}

This should be an exact match for 4 records.

Phase 2 (Search for a range and my ultimate goal)
I need to take this and search for a range.  According to
http://stackoverflow.com/questions/355937/filtering-sphinx-search-res...

I should be able to do a range like:

  :conditions => {:pub_date =>
"8/1/2008".to_time.to_i.."9/10/2008".to_time.to_i}

How can I fix this?


    Reply to author     Forward            Rate this post: Text for clearing space
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Finding_Zion  
View profile  
 More options Jan 20 2009, 6:07 pm
From: Finding_Zion <jeremy.g.peter...@gmail.com>
Date: Tue, 20 Jan 2009 14:07:54 -0800 (PST)
Local: Tues, Jan 20 2009 6:07 pm
Subject: Re: Searching for Dates
I figured out what the problem was with the way I set up the index.  I
had to set the type to datetime, perhaps it has to do with my database
table using a date type.

In the model:
  has data.pub_date, :type => :datetime, :as => :pub_date

Searching:
def advanced_search
    conditions = filter_type
    search = params.dup.delete_if {|k,v| !"title author id cb_number
season isbn".include? k}# List items to include
    search.each do |key, value|
      conditions[key.to_sym] = value if !value.blank?
    end

    # Search Date range
    if !params[:pub_date][:start].blank? && !params[:pub_date]
[:start].blank?
      start_date = params[:pub_date][:start].to_i
      end_date = params[:pub_date][:end].to_time.advance(:days =>
1).to_i
      conditions[:pub_date] = start_date..end_date
    end

    Project.search :include => :data,
      :conditions => conditions,
      :page => params[:page] || 1,
      :order => "title asc",
      :per_page => 10,
      :match_mode => :extended
  end

On Jan 20, 12:28 pm, Finding_Zion <jeremy.g.peter...@gmail.com> wrote:


    Reply to author     Forward            Rate this post: Text for clearing space
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pat Allan  
View profile  
 More options Jan 21 2009, 12:02 am
From: Pat Allan <p...@freelancing-gods.com>
Date: Wed, 21 Jan 2009 11:02:06 +0700
Local: Wed, Jan 21 2009 12:02 am
Subject: Re: [ts] Re: Searching for Dates
Hi Jeremy

In the latest versions of Thinking Sphinx, you shouldn't need the  
explicit :type => :datetime - and you also shouldn't need .to_i for  
the range arguments. If you're using the latest and it's not working,  
then we can investigate further - but good to know you've got  
something that does the job at the moment.

Cheers

--
Pat

On 21/01/2009, at 5:07 AM, Finding_Zion wrote:


    Reply to author     Forward            Rate this post: Text for clearing space
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Peterson  
View profile  
I upgraded ts and it takes care of the .to_i.  However I still need to explicitly call :type => datetime.  I think this is because I am using just a date field. Sweet, Jeremy On Tue, Jan 20, 2009 at 10:02 PM, Pat Allan <p...@freelancing-gods.com>wrote: - Hide quoted text -- Show quoted text -> Hi Jeremy > In the latest versions of Thinking Sphinx, you shouldn't need the > explicit :type => :datetime - and you also shouldn't need .to_i for > the range arguments. If you're using the latest and it's not working, > then we can investigate further - but good to know you've got > something that does the job at the moment. > Cheers > -- > Pat > On 21/01/2009, at 5:07 AM, Finding_Zion wrote: > > I figured out what the problem was with the way I set up the index.  I > > had to set the type to datetime, perhaps it has to do with my database > > table using a date type. > > In the model: > >  has data.pub_date, :type => :datetime, :as => :pub_date > > Searching: > > def advanced_search > >    conditions = filter_type > >    search = params.dup.delete_if {|k,v| !"title author id cb_number > > season isbn".include? k}# List items to include > >    search.each do |key, value| > >      conditions[key.to_sym] = value if !value.blank? > >    end > >    # Search Date range > >    if !params[:pub_date][:start].blank? && !params[:pub_date] > > [:start].blank? > >      start_date = params[:pub_date][:start].to_i > >      end_date = params[:pub_date][:end].to_time.advance(:days => > > 1).to_i > >      conditions[:pub_date] = start_date..end_date > >    end > >    Project.search :include => :data, > >      :conditions => conditions, > >      :page => params[:page] || 1, > >      :order => "title asc", > >      :per_page => 10, > >      :match_mode => :extended > >  end > > On Jan 20, 12:28 pm, Finding_Zion <jeremy.g.peter...@gmail.com> wrote: > >> I need to add a range search for dates.  The usage guide mentions > >> that > >> dates are converted to timestamps, however it would be nice to have > >> some examples for how to search them.  This is what I have so far and > >> it isn't search the way I'd expect. > >> In the model: > >>   indexes data.pub_date, :as => :pub_date > >> Phase 1 (Search for a date field) > >> When searching, I add the following condition. > >>   :conditions => {:pub_date => "8/31/2008".to_time.to_i} > >> This should be an exact match for 4 records. > >> Phase 2 (Search for a range and my ultimate goal) > >> I need to take this and search for a range.  According tohttp:// > stackoverflow.com/questions/355937/filtering-sphinx-search-res > >> ... > >> I should be able to do a range like: > >>   :conditions => {:pub_date => > >> "8/1/2008".to_time.to_i.."9/10/2008".to_time.to_i} > >> How can I fix this?
 More options Jan 21 2009, 4:03 pm
From: Jeremy Peterson <jeremy.g.peter...@gmail.com>
Date: Wed, 21 Jan 2009 14:03:25 -0600
Local: Wed, Jan 21 2009 4:03 pm
Subject: Re: [ts] Re: Searching for Dates

I upgraded ts and it takes care of the .to_i.  However I still need to
explicitly call :type => datetime.  I think this is because I am using just
a date field.

Sweet,

Jeremy

On Tue, Jan 20, 2009 at 10:02 PM, Pat Allan <p...@freelancing-gods.com>wrote:


    Reply to author     Forward            Rate this post: Text for clearing space
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pat Allan  
View profile  
 More options Jan 21 2009, 10:45 pm
From: Pat Allan <p...@freelancing-gods.com>
Date: Thu, 22 Jan 2009 09:45:23 +0700
Local: Wed, Jan 21 2009 10:45 pm
Subject: Re: [ts] Re: Searching for Dates
Hmm, I have a test for date columns... odd.
At least to_i is covered.

Cheers

--  
Pat

On 22/01/2009, at 3:03 AM, Jeremy Peterson wrote:


    Reply to author     Forward            Rate this post: Text for clearing space
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google