searching hibernate…

Hibernate Search (Search) is well-documented, with a clean and easy to use API. The first line in its architectural overview states that it “…consists of an indexing and an index search engine. Both are backed by Apache Lucene.” It’s really that simple. You’ll still insert/update records as you always have. Except now, you have the added benefit of using free-text queries to search your data. You aren’t forced to now search in one way or another – just more freedom (pun intended). If you have experience with Hibernate’s Query, Criteria, or JPA’s Query APIs, you are already half-way there.

getting it done…

To get this working, I had about four major steps. First, I added hibernate-commons-annotation, hibernate-search.jar and lucene-core.jar. Next, I then went about converting some of my named queries to lucene queries, but that was more busy work than anything. Third, I had to make my base Daos Search-aware, which really means adding three methods: one for (re)indexing (that gets called at startup), and two for creating org.apache.lucene.search.Querys – one for default field queries, and another for multi-field queries.

slight bump in the road…

My fourth step was less installation, and more problem solving. I ran into an issue when I tried top apply type filtering. It seems that the ObjectLoader and QueryLoader handled items loaded from the current Hibernate Session a bit differently. The ObjectLoader attempts to initialize the loaded item, just in case. While the QueryLoader only adds a loaded item as a result if it is already initialized. This may be correct, but it didn’t work for me. After some debugging and testing, I found that just as the ObjectLoader, initializing the Session-loaded object worked fine. After no word from the forum, I made the relevant changes to my local Search build.

Overall, getting Search up and running was mostly straight forward. Based on the fairly small dataset, I have no need for the sharding/partitioning functionality. I have heard that keeping indices in synch can become an issue. I don’t know if that was before or after the Search’ JMS-based workers.

Update: I did get a response on the Hibernate forum. There may be an additional feature added, but for now I can move forward.

This entry was posted in Technical stuff. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.