[prev in list] [next in list] [prev in thread] [next in thread] 

List:       solr-user
Subject:    'New' "Date Math" parsing code in Solr
From:       Chris Hostetter <hossman_lucene () fucit ! org>
Date:       2006-12-13 20:03:53
Message-ID: Pine.LNX.4.58.0612131147440.28612 () hal ! rescomp ! berkeley ! edu
[Download RAW message or body]


(I have this nasty habit of commiting cool things to Solr that should be
announced on solr-user, and then deciding I'll wait untill they are in a
nightly snapshot before I send an email about them -- and then forgetting
that I never sent the mail).

A while back I added some functionality to the DateField class which
extends it's parsing abilities so that it can recognize strings like
"NOW", "NOW+1DAY", "NOW+1DAY-3HOURS", and even "NOW/MONTH+3MONTHS" which
means round down to the nearest month, then add three months.

You can play with this syntax and see what exactly it does with various
inputs by looking at the "parsedquery" debug info for any date field, if
you are running the example config from Solr something like this will
work...

http://localhost:8983/solr/select?version=2.1&q=field_dt%3A%5BNOW+TO+NOW%2FDAY%2B1MONTH%5D&start=0&rows=0&debugQuery=on


This syntax was added to not only make it easier to run quick data
inspection queries like "startDate:[NOW TO *]" but also so that *relative*
date based queries can be included directly in the default query options
for request handlers configured in solrconfig.xml.  For example, if you
only want to let people search articles less then a month old, you could
put...

     <str name="fq">pubDate:[NOW/DAY-1MONTH]</str>

...in your requestHandler config, and that cached filter query will be
reusable for 24 hours.

This syntax is supported anywhere Solr parses a DateField, so it can even
be used in <field> values when sending <add><doc> messages.

More info can be found in the javadocs...

http://incubator.apache.org/solr/docs/api/org/apache/solr/schema/DateField.html
http://incubator.apache.org/solr/docs/api/org/apache/solr/util/DateMathParser.html


-Hoss


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic