tags:

views:

1325

answers:

3

How do i group search results returned by Lucene by fields?

Thanks!

A: 

https://issues.apache.org/jira/browse/LUCENE-1421

it appears that you cant. there is possibly a workaround though: theres a thread here which outlines how someone else has done it : here

gcrain
A: 

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.

erickson
A: 

Yes,I need a true GroupBy behaviour similar to SQL Server's.