lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <>
Subject 'New' "Date Math" parsing code in Solr
Date Wed, 13 Dec 2006 20:03:53 GMT

(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


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

     <str name="fq">pubDate:[NOW/DAY-1MONTH]</str> 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...


View raw message