Faceting on date fields

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Faceting on date fields

Rhys Palmer-2
Hi all,

I've having some problems getting faceting to work correctly on date
fields. For each document I index in solr I store a created date.
ie. <date name="created_date_dt">1993-01-01T00:00:00.000Z</date>

What I'm trying to do is for any search query, facet on year part of the
created date using:
facet.date = created_date_dt
f.created_date_dt.facet.date.start = NOW/YEAR-100YEARS
f.created_date_dt.facet.date.end = NOW/YEAR+1YEAR
f.created_date_dt.facet.date.gap = +1YEAR

If I do a search that returns 1 result with a created date of
"1993-01-01T00:00:00.000Z", I get this:
<lst name="facet_dates">
<lst name="created_date_dt">
   ...
  <int name="1992-01-01T00:00:00.000Z">1</int>
  <int name="1993-01-01T00:00:00.000Z">1</int>
   ...
</lst>

Am I better off storing the year separately in an integer field and
faceting on that?

Thanks,
Rhys
Reply | Threaded
Open this post in threaded view
|

Re: Faceting on date fields

hossman

: If I do a search that returns 1 result with a created date of
: "1993-01-01T00:00:00.000Z", I get this:
: <lst name="facet_dates">
: <lst name="created_date_dt">
:    ...
:   <int name="1992-01-01T00:00:00.000Z">1</int>
:   <int name="1993-01-01T00:00:00.000Z">1</int>

This is because the "range queries" used in date faceting are "inclusive"
of both bounding dates ... this was the simplest solution that we came up
with at the time.  There was disucssion at one time about adding
additional options to control which bounds were inclusive and which were
exclusive but I don't think anyone ever proposed anything concrete (or
opend a Jira issue)

: Am I better off storing the year separately in an integer field and
: faceting on that?

you mean using facet.field?  that will certianly work.  

the other worarround (which is admitedly really hackish) is to
add/subtract a few milliseconds, either to the dates of docs when you
index them, or to your facet.date.start param (in your case: either add
amilli to the docs, or subtract a milli from the param)





-Hoss