How do i group search results returned by Lucene by fields?
Thanks!
How do i group search results returned by Lucene by fields?
Thanks!
It's not clear whether you want a true SQL-like "GROUP BY" behavior, or merely an "ORDER BY" behavior. There's nothing like aggregation functions in Lucene, so "GROUP BY" would have to implemented in your application, on top of Lucene.
However, sorting by fields is fairly easy. Make sure the desired field is indexed, and create a org.apache.lucene.search.Sort object to be passed as part of the search criteria; most search methods have an overload that accepts a Sort instance.
If you were to implement your own "GROUP BY" logic, having the results "ORDERED BY" the correct fields is a helpful first step.