Date range queries return zero results

Hello,

I am having trouble getting data ranges to work correctly. I am using
the following command to load the db:

index << {:title => row[7].to_i,
:date => Date.strptime(row[3], ‘%Y-%m-%d’),
:page_id => row[5].to_i,
:page => row[6].to_i,
:content_type => row[1].to_i,
:article_id => row[4].to_i,
:label => row[2],
:label_sort => row[8],
:content => row[0]
}

Notice “Date.strptime(row[3], ‘%Y-%m-%d’)”…

When I query (ex. +label:barbara) I get results in the form:

{:label=>“NEW TOOL FOR BARBERS.”, :page_id=>“36”, :label_sort=>“NEW TOOL
FOR BARBERS.”, :page=>“4”, :date=>“1900-03-02”, :content_type=>“19”,
:title=>“1”, :article_id=>“7855”, :content=>" NEW TOOL FOR BARBERS."}

Which looks correct to me but if I modify the query to include a date
range like “+label:barbara +data:{19000101 19010101}” or even
“+label:barbara +data:(>=19000101 AND <= 19010101}” I get 0 results.
Does anybody know what I am doing incorrectly?

I am using Windows Vista, Ferret version 0.11.5 mswin32.

Benjamin

Hi!

I’d say your problem is that you index your dates with ‘-’ separators
between year, month and day, but your range queries don’t have these.

You should get this working (and better performance because of faster
integer based sorting) by indexing your dates as ‘%Y%m%d’.

Cheers,
Jens

On Fri, Jan 11, 2008 at 11:14:54AM -0800, Benjamin A. wrote:

            :article_id => row[4].to_i,

FOR BARBERS.", :page=>“4”, :date=>“1900-03-02”, :content_type=>“19”,
Benjamin


Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk


Jens Krämer
http://www.jkraemer.net/ - Blog
http://www.omdb.org/ - The new free film database

On Fri, 2008-01-11 at 11:14 -0800, Benjamin A. wrote:

Hello,

I am having trouble getting data ranges to work correctly. I am using
the following command to load the db:

Hi Benjamin,

the .to_s method for the Date object returns a date formatted like
"2007-12-25, so for one you’re searching for a string that doesn’t exist
in the index.

Secondly, I’m pretty sure the hypens in that string will be tokenized by
the Ferret tokenizer, so will end up in the database as separate parts,
so a range query would be slow (or not work, not certain).

Try explicitly returning the date in a useful format when putting it in
the index:

index << {:title => row[7].to_i,
:date => Date.strptime(row[3],
‘%Y-%m-%d’).strftime(“%Y%m%d”),
:page_id => row[5].to_i,
:page => row[6].to_i,
:content_type => row[1].to_i,
:article_id => row[4].to_i,
:label => row[2],
:label_sort => row[8],
:content => row[0]
}
John

http://www.brightbox.co.uk - UK Ruby on Rails hosting

Hello,

It worked changing the format too %Y%m%d. So, Ruby does not really
handle dates directly? I would have thought Ferret would have parsed
the Date object internally. Anyways, thanks for the help!

Benjamin