Hibernate Search

In this section we will learn about Hibernate Search, which is used create full text index using apache Lucene engine.

Hibernate Search

Hibernate Search

     

In this section we will learn about Hibernate Search, which is used create full text index using apache Lucene engine. Then the index data can be used to run the full text search.

Introduction to Hibernate Search

Hibernate is a high performance, ORM framework that is being used to develop large-scale enterprise applications in Java technology.

Hibernate search integrates with the Java Persistence API and Apache Lucene. Apache Lucene has high performance search engine capabilities. In Hibernate Search, both the object-relational mapping capacity of JPA/Hibernate and the full text search capacity of Lucene are integrated. It mends the disadvantages of SQL query of RDBMS, which is insufficient for full text searching. Hibernate search also uses Annotations and EntityManager.

Lucene encourages Hibernate Search by bringing out its advantages over RDBMS SQL search, which can’t be used for fulltext search. Lucene covers all types of full text search and can be used to develop search facility for web sites.

Some basic key features are common in Hibernate and Lucene as both provide CRUD access to the primary data storage and define an elementary data unit: the Entity (persistence model class) in Hibernate/JPA and the Document in Lucene. Besides it, the same programming concepts like deferred commit, filter, query expression and query API- are common that functions in Hibernate / JPA and Lucene.

But, there are also some differences that recognise their own identity like- Hibernate / JPA promotes domain model-oriented programming that encourage developers to work out a rich domain-object graph while Lucene only deals with a single, built-in data model. In Hibernate / JPA, the rich domain-object graph usually represents the complexities of the real-world business through object association, inheritance, polymorphism, composition, and collections, whereas in Lucene, the built-in-data model it provides a simple document class, which simplify the search operation and even programmers, can execute complex search queries.

Uses of same persistence context in both Hibernate/JPA (Session/EntityManager) and Lucene (Document) makes indexing processes transparent to the developers enabling the deveopment around hibernate search easier.

Some of the features of Hibernate search can be described as below-

  • Lucene Integration: Lucene provides a powerful search engine capability to Hibernate search.
  • Automatic insertion and modification of data: The search index in Hibernate is automatically updated when an object is inserted and updated by Hibernate.
  • Support for many complex kind of search: Hibernate supports many complex searches like- wild card search which helps in search words having some letters in common (but not all the letters); multi-word text search; approximation or synonym search etc.
  • Search clustering: Hibernate provides clustering solutions through a Java Messaging Service API (which creates, sends, receives and reads) and asynchronous querying/indexing system.
  • Direct use of Lucene API: Hibernate provides the facility to use Lucene API directly to create some particular complex queries.
  • Automatic Lucene Management: Hibernate search automatically updates and manages the Lucene Index by using the Lucene API efficiently.

The main object of Hibernate Search includes-

  • Ease of use: Hibernate search takes care of most of the problems and provide us the freedom to concentrate on the remaining and more difficult jobs.
  • Consistency with the Hibernate/JPA programming model: Hibernate search integrates with the features of existing hibernate/JPA programming model.