Hibernate Annotations 3.2.1 – Lucene sort
Keeping database and Lucene index in sync is easily done using the new Lucene-Hibernate integration.
Just place the default org.hibernate.search.event.FullTextIndexEventListener on Hibernate’s lifecycle methods, configure the Lucene annotations in classes you want to search and you’re ready to go. For custom operations such as persisting custom classes, you can write bridges where you can create custom fields in the index.
Save/update/deletes of your hibernate objects will propagate in Lucene index. A full reindex can be implemented as well using a custom the new FullTextSession class.
Everything is great on the keeping in sync part, but how about doing actual searches?
The intent was to wrap actual Lucene queries and have them transformed into Hibernate queries, empowering the API user with all the API Hibernate provides for query manipulation (eg. pagination). Problem is getting a hold of the actual Lucene index is no longer possible. All that nicely created and maintained in sync index cannot be used with real Lucene queries, using Lucene API to extract the information.
A simple problem was using Lucene to do a Sort for me, turns out that current API does not provide that. As I understand, 3.3.0 will allow direct access to Lucene Directory (see here). To get around that you can use something similar to SearchDAO.java using the same index access as Lucene-Hibernate integration is using.