Hi Eric,

I tried looking for a sample code to sort on Date but was unable to find
one? I am using 3.4 version.
Any idea as to where I can find one?

Thanks a ton

On Fri, Jan 27, 2012 at 8:13 AM, Erick Erickson <erickerick...@gmail.com>wrote:

> Why not just sort on date and take the first doc returned in the list?
>
> Best
> Erick
>
> On Thu, Jan 26, 2012 at 10:33 AM, Peter Markey <sudoma...@gmail.com>
> wrote:
> > Hello,
> >
> > I am building a custom component in Solr and I am trying to construct a
> > query to get the latest (based on a date field) DocID using
> SolrIndexSearcher.
> > Below is a short snippet of my code:
> >
> > SolrIndexSearcher searcher =
> > final SchemaField sf = searcher.getSchema().getField(dateField);
> > //dateField is one of the fields that contains timestamp of the record
> >
> > final IndexSchema schema = searcher.getSchema();
> >
> > Query rangeQ = ((DateField)(sf.getType())).getRangeQuery(null,
> sf,null,NOW,
> > false,true); //NOW is current Date
> >
> > DocList dateDocs = searcher.getDocList(rangeQ, base, null, 0, 1); //base
> is
> > a set of doc filters to limit search
> >
> >
> >
> > Though I get some docs that satisfy the query, my goal is to get the doc
> > whose's dateField is closest to the current time. Are there any other
> > queries I can employ for this?
> >
> >
> > Thanks a lot for any suggestions.
>

Reply via email to