简体   繁体   中英

How to query for maximum field value in Lucene.Net?

We want to be able to return a single document with a maximum value for a particular field. A typical example would be,

max(date_time_field:*)

which returns the latest document in the index.

Is there any support for something like this in Lucene.Net?

I'm not sure how you are querying your index, but you can certainly order by the field in question, and then simply take the top document:

var sortBy = new Sort(new SortField("date_time_field", SortField.DOUBLE, true));
var hits = ... IndexSearcher.Search(query, null, 1, sortBy));

...

var doc = searcher.IndexSearcher.Doc(hits.ScoreDocs[0]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM