All documents in a Solr index have an "added" field containing the ISO 8601 date in which the document was added to Solr.
<result name="response" numFound="34587104" start="0">
<doc>
<date name="added">2013-03-04T01:00:26Z</date>
<str name="text">Hello, world!</str>
<str name="id">93416604d274d28a44e14a9535bb9e6e1db3d851</str>
<str name="_version_">1428536769315340290</str>
</doc>
<result/>
Assuming that no documents are removed, how might I get a count of how many documents exist in the index per day? For instance, in order to know how many documents were in the index on 2013-03-05 I could query q=added:[* TO 2013-03-05T00:00:00Z]
. However, I need to know how many documents were in the index for each day from one month ago until today.
One solution might be to query how many documents were in the index on the date one month ago, then facet on how many documents were added each day and then add them to a cumulative count. PseudoCode:
initial_count = q=added:[* TO NOW/MONTH-1MONTH]
running_total = initial_count;
daily_added_array = facet.range=added
& f.added.facet.range.start=NOW/MONTH-1MONTH
& f.added.facet.range.end=NOW/DAY-1DAY
& f.added.facet.range.gap=+1DAY
foreach (daily_added_array as day) {
running_total += day;
printf(running_total);
}
However this method seems extremely fragile and prone to error.
Is there a way to get the cumulative amount of documents in the index per day?