Download a Working Hibernate Search Example

Posted on May 20, 2007 by Guy Snir
Filed Under Open Source, Java, Database |

I got a copy of a working example of the Hibernate Search project, thanks to Mr. Amir Kibbar.

According to the official project homepage: “Hibernate Search brings the power of full text search engines to the persistence domain model and Hibernate experience, through transparent configuration (Hibernate Annotations) and a common API.”

Underneath the covers Hibernate Search uses Apache Lucene to implement the searching capabilities. With this project you will be able to Insert / Update / Delete like you would normally do with Hibernate, and Hibernate Search will keep the Lucene indexes in sync - This then enables you to perform a “search” on your data and get a list of results back in the form of your business objects.

In the attached example (that you can unzip with bzip2) you will find a simple Department and Employee scenario where you can insert new departments or employees and then perform a free text search on your data, as a result you will get back Department objects, Employee objects or both.

This is a powerful capability and I hope this example will help you in learning about it.

Important notes about the example:

And again, thanks to Mr. Amir Kibbar for supplying this useful example.

Guy

AddThis Social Bookmark Button

Comments

14 Responses to “Download a Working Hibernate Search Example”

  1. Manju on August 4th, 2007 10:30 pm

    Hello,
    I was trying to extract the archive using the utility that you mentioned(Bzip)…but am not able to do so.
    Can you let me know if I can get the same in another format?
    Thanks,
    Manju

  2. Guy Snir on August 5th, 2007 6:52 am

    Hi Manju,

    I have uploaded a zip version:

    http://www.opensourceguy.net/wp-content/uploads/hibernate-search.zip

    I hope it works for you this time

    Guy

  3. Manju on August 9th, 2007 12:09 pm

    Hey Guy,
    Thanks for the code.
    But I still am not able to understand what configuration steps I need to do to get the data that I already have in my MySQL database indexed.
    I noticed that you have the hibernate search and hibernate annotations jar in the classpath.
    After specifying the index directory in hibernate.cfg.xml, how do get the Index created so that later when I use the query (like the ones in the SearchResults.java class), i can use the index.
    Please help me.
    thanks,
    Manju

  4. Amir on August 15th, 2007 4:22 am

    Hi Manju,

    Yes - you need to create an initial index of your already persisted objects.

    To do this, once you set up the hibernate search environment, you can simply fetch all the entities from the database. This will create the index for you.

    This operation need only be executed ONCE, and can be done with a simple hibernate query:
    “from java.lang.Object”
    This query will fetch all entities from the database.

    Amir

  5. Roger Taylor on September 4th, 2007 5:58 am

    Hello, is this project building with eclipse?

  6. Guy Snir on September 4th, 2007 6:11 am

    Hi Roger,

    If you use this procedure it should work:

    http://www.hibernate.org/422.html#A5

    Regards,
    Guy

  7. Manimaran on September 6th, 2007 1:53 am

    Hi,

    I don’t understand the procedures to execute hibernate Search example. Can anyone help me out of this. The information here is insufficient.

    Thanks
    Mani Maran

  8. Amir on September 6th, 2007 2:13 am

    Hi Mani,

    I’m not sure what you mean, I think Roger and Guy confused you a little.

    Roger’s problem was creating an eclipse project from this example. This can be done, as explained by Guy, by using mvn eclipse:eclipse.

    I think you are having problems running the example.

    The example defines two entities: Employee and Department. These entities are annotated with the new hibernate search annotations. This is the essence of the example - how to use these annotations.

    To run the example, you need to execute the junit test: SearchResults. This test inserts some data to the database, then fetches it by querying using a hibernate search query.

    You do NOT need a database for this example. The example uses Apache’s DerbyDB as an embedded database.

    If you are having any more problems with this, do not hesitate to ask.

    Amir

  9. Manimaran on September 7th, 2007 2:25 am

    Amir,

    We are developing Knowledge Management System for Support center. Support people has to answer customer queries. Knowledge base is a very large data base since the support is for e-file. Its a online chat support center, Support people has to answer the customer immediately. Support people will give the customer queries as it is to search database. Will Hibernate Search API is right Choice?

    Please suggest me on this and if you can give me some more resources(samples) in hibernate search, will be very helpful for me.

    Thanks a lot for your reply

    Regards
    Mani Maran

  10. Amir on September 9th, 2007 4:48 am

    Mani,

    I think that Hibernate Search is the text book choice for your kind of application. Check out the main download page of Hibernate search: http://hibernate.org/410.html
    You’ll see that the point of this Hibernate extension if to index domain objects.

    Hibernate search stores an index of the domain object locally. This index can later be used to query and retrieve these objects. The difference between a search-based query and a regular HQL is that the search-based query just queries the index, and if your search term fits an indexes property it will cause the object to be retrieved. When using HQL you need to know where the searched term will be - in which object and in which property, or create a very large and very generic query - which is hard to maintain and slow on performance.

    Amir

  11. Raghav on November 26th, 2007 6:12 am

    Hi,

    Could anyone provide me with a Hibernate Search example which doesn’t use annotations?

    Where do I set these properties if I dont use Annotations, in Properties/XML?

  12. Ambika on January 29th, 2008 7:40 am

    Hi Guy,

    As a fresher to start with this example, what are all the steps required. I would like to know how would i able to execute this application, should i know junit, system should be configured with maven etc., If possible could u give us the steps to run the project, which will be very helpful for the beginners.

    Ambika

  13. Amir on January 29th, 2008 8:36 am

    Hi Ambika,

    all you really need is a JDK (1.5 or above), and Maven2 installed (2.0.x).

    Install both tools, download the example and run mvn install, then mvn test.

    Amir

  14. Ambika on January 29th, 2008 9:01 am

    Amir,

    thanks a lot, to clear me. Actually i dont no about maven, that is why i asked about. Now i tried installing maven and trying to run the application.

    One more i would like to ask you, this example is using java persistence, if i want to connect to my own database then is there is any example to do that or any modification doing to this application will be enough.

    -Ambika