How can I filter resent data from matched result by grouping date field
for example
I annote my entity as follows
hsno column for
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
date column for
@Field(index = Index.YES, analyze=Analyze.NO, store = Store.YES)
kor column for
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
and I have result from keyword search
hsno date
12345 2017-01-01
12345 2018-03-01
123456 2017-01-01
123456 2018-01-01
from the above result
I only want recent result grouping by hsno as follows
12345 2018-03-01
123456 2018-01-01
If your main filters only apply to fields that are always the same for a given “hsno”, the easiest way to achieve this would be to normalize your schema, moving the “hsno” and directly related information to a separate entity/table (let’s name it “HSEntity”), with an association/foreign key to the entity/table containing the dates (let’s name it “EventEntity”).
Then you could index “HSEntity” and add an @IndexedEmbedded
on the association targeting “EventEntity”.
Finally, you would query “HSEntity”, and transform the results to get the latest “EventEntity” for each “HSEntity”.
If your main filters also apply to fields that are not always the same for a given “hsno”, or if changing your database schema is not an option, I’m affraid you’re out of luck. As we already mentioned in an answer to a similar question, grouping is not supported yet in Hibernate Search, mainly because there wasn’t enough demand for this feature to make it to the top of our priority list.
If you want to see a feature added to Hibernate Search, feel free to create a ticket on our JIRA instance, describing in details your use case and giving us an idea of the API you would expect.
I am late.
Thank you yoann.
I have no option to change database schema.
as you mentioned I will search using an IndexReader.
Thank you again.