How do you specify a date facet query in Solr?
When I do a query to Solr, I get these facet_counts back:
'facet_counts' => {
'facet_dates' => {
'photo_added' => {
'2009-12-28T18:00:00Z' => 396386,
'2010-05-28T18:00:00Z' => 415370,
'gap' => '+1MONTH',
'end' => '2011-02-28T18:00:00Z',
},
},
},
However, when I add any one of these parameters to a q=*:*
query:
fq=photo_added:2009-12-28T18:00:00Z
fq=photo_added:2009-12-28T18%3A00%3A00Z
I receive this as a response:
HTTP ERROR 400: Invalid Date String:'2009-12-28T18'
When I add any one of these parameters 开发者_开发知识库to a q=*:*
query:
fq=photo_added:"2009-12-28T18:00:00Z"
fq=photo_added:"2009-12-28T18%3A00%3A00Z"
fq%3Dphoto_added%3A%222009-12-28T18%3A00%3A00Z%22
fq=photo_added%3A"2009-12-28T18%3A00%3A00Z"
I receive this in the response:
<result name="response" numFound="0" start="0"/>
But when I don't have an fq=
constraint on my query, I get numFound="8001000"
, so it's definitely something wrong with the fq=
constraint.
How can I do a date facet query that works?
I think you're misinterpreting the date facet results. IIRC, since you defined a gap of 1 month, the result '2009-12-28T18:00:00Z' => 396386
means that between 2009-12-28T18:00:00Z and 2010-01-28T18:00:00Z (one month) there are 396386 results.
But then you're running a filter query with an exact date, and you get no results because no document matches exactly that date and time. If you want to fetch those 396386 documents, run a filter query with a range between the dates I mentioned above: fq=photo_added:[2009-12-28T18:00:00Z TO 2010-01-28T18:00:00Z]
精彩评论