0
votes

I have an example schema like:

id:1,date:2012-05-01,parent:p1
id:1,date:2012-05-01,parent:p2
id:1,date:2012-05-01,parent:p3
id:1,date:2012-05-02,parent:p1
id:1,date:2012-05-02,parent:p4

I would like to pefrorm a range query on "date" and know how many new/unique parents occured each day. In other words i would like to see how many NEW parents were added through time. For the given data the output should look like:

2012-04-31:0 (no parents existed an that time)
2012-05-01:3 (because three new parents occured at 2012-05-01: p1,p2,p3) 
2012-05-02:4 (which is 3 parents from 2012-05-01 and 1 new unique parent p4 occured at 2012-05-02 which gives a total of 4)
2012-05-03:4 (no new parent was added this day...)

Is this kind of query even possible in SOLR?

1

1 Answers

2
votes

Yes this should be fairly simple if I understand your question correctly. Adding something like

fq=date:[2012-05-05T00:00:00Z TO 2012-05-06T00:00:00Z]

to your query will fetch you all documents with a date between 5 May and 6 May. Make sure to store your dates in ISO 8601 format.

For more, check out the date examples here: http://wiki.apache.org/solr/SolrQuerySyntax

EDIT: I understood your question better now - you're looking for "group collapsing."

Try

&group=true&group.field=parent&group.limit=1

and count the number of documents returned.

If you want them with values for each date, you'll want to facet by date:

&facet=true&facet.field=date