Search code examples
solrfacetfaceted-search

check solr facet query if it is greater than specific datetime value


I have the following in solr

<str name="id">2</str>
<arr name="parsed">
    <str>2011-11-01 13:40:08.0</str>
</arr>
<arr name="person">
    <str>Harsh Snehanshu | Apoorv Jain</str>
</arr>

now if i want to search for jain, simply i will use this query

http://192.168.1.135:8888/solr/MyCol/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on&facet=true&fq=person:jain

now the question is: how can i search for entries that have been parsed AFTER (greater than) 2011-11-01 13:00:00 or (between 2011-11-01 12:30:00 and 2011-11-01 13:30:00)??
Thanks for your help


Solution

  • The parsed field needs to be defined as a datefield.

    e.g.

    schema.xml -

    Field type of TrieDateField should be available -

    <fieldType name="tdate" class="solr.TrieDateField" omitNorms="true" precisionStep="6" positionIncrementGap="0"/>
    

    Map the prased field with the tdate field type as -

    <field name="parsed" type="tdate" indexed="true" stored="true"/>
    

    So, when indexed, the response it would appear as <date name="parsed">2009-04-28T00:00:00Z</date>

    This would allow you to use date filter queries for the datefield.

    e.g. fq=parsed:[1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z]

    Also for search it would be better to use q=person:jain.
    Use filter queries for restricting the documents rather than searching.