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 <[email protected]> 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?
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---