By the way: if you only need to count documents (count groups) HitCollector is a good choice. If you only count you don't need to sort anything.
ninaS wrote:
Hello,
yes I tried HitCollector but I am not satisfied with it because you can not use sorting with HitCollector unless you implement a way to use TopFieldTocCollector. I did not manage to do that in a performant way.
It is easier to first do a normal search und "group by" afterwards:
Iterate through the result documents and take one of each group. Each document has a groupingKey. I remember which groupingKey is already used and don't take another document of this group into the result list.
Regards,
Nina