Saturday, January 7, 2012

Combining the power of Hibernate Search and Solr

For people working with Hibernate to manage their objects' persistence, Hibernate search is a real savior. After trying to develop similar functionality (collecting all objects changes and sending them to a full text search engine upon transaction commit) you find out pretty fast that there are lots of pitfalls out there.
On the other hand Solr has some significant advantages (like 1:m facets if you need it) which make it a better decision on some scenarios.
Since Hibernate Search is written in a very extendable way, it turns out there is an easy option to combine both together. This way you get Hibernate Search to do all the Hibernate monitoring hard work and collecting all changes, while you can use Solr to do all searches and faceting work.
By configuring Hibernate Search default worker backend with the "hibernate.search.default.worker.backend" configuration parameter ( or by configuring Hibernate Search to forward all changes through JMS) you can catch all changes in a very convenient format and forward them to Solr using the SolrJ client interface.
Although in most scenarios you will probably prefer working with Hibernate search for both updates and queries, if for some reason you need Solr and you use Hibernate, you can still get a lot from Hibernate search.
You can build a system in a very short time where FTS fields are annotated using Hibernate Search annotations and all updates end up in the Solr server. Then you can use Solr for queries and configure it to return only the IDs of the relevant documents / objects. Afterwards you can use the Ids list with hibernate to translate the list to hibernate objects.
Any comments / inputs are always welcomed...
If you are intrested I've written a small example which shows the main concepts at:
https://github.com/avner-levy/hibernate_search_solr_integration

    Avner

44 comments:

  1. I am trying to use your example code but without spring, and it's just not working, I need to integrate a plain hibernate jpa module and the solr adpater/integrator (HibernateSearchSolrWorkerBackend) is never triggered, do you have an example of what you have to put in the persistence xml?

    ReplyDelete
    Replies
    1. Since I'm working with spring I don't have such example but these are regular hibernate properties so there should be enough examples on the net.

      Delete
  2. Yeah I think you were right, my problem was that I am using an older version of jpa and hibernate-search.. so your code example doesn't work for me because the interface of the custom back-end worker is completely different (BackendQueueProcessorFactory for hibernate-search 3.1.1GA).

    ReplyDelete
  3. Enjoyed your approach to explaining how it works, hope to see more blog posts from you. thank you!

    Hibernate Online Training | Java Online Training


    Hibernate Training in Chennai Java Training in Chennai

    ReplyDelete
  4. Thanks for the comment! It is always good to know it was helpful for someone.

    ReplyDelete
  5. Enjoyed your approach to explaining how it works, hope to see more blog posts from you. thank you!

    Hibernate Online Training | Java Online Training


    Hibernate Training in Chennai Java Training in Chennai

    ReplyDelete
  6. Hibernate Online Training Hibernate Online Training

    Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training

    ReplyDelete
  7. I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
    Devops Training courses
    python Training in chennai
    Devops Training in Bangalore

    ReplyDelete
  8. I was recommended this web site by means of my cousin.
    I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!

    selenium training in Chennai
    selenium training in Tambaram
    selenium training in Velachery
    selenium training in Omr
    selenium training in Annanagar


    After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
    Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in

    ReplyDelete
  9. You got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.
    Python Online training
    python Course institute in Chennai
    Python Course institute in Bangalore

    ReplyDelete
  10. This is best one article so far I have read online, I would like to appreciate you for making it very simple and easy
    Regards,
    Devops Training in Chennai | Devops Certification in Chennai

    ReplyDelete
  11. This is a nice Site to watch out for and we provided information on
    vidmate make sure you can check it out and keep on visiting our Site.

    ReplyDelete
  12. Download and install Vidmate App which is the best HD video downloader software available for Android. Get free latest HD movies, songs, and your favorite TV shows

    ReplyDelete
  13. It is easy ( cemboard ) to win trust that is easy to destroy, it ( giá tấm cemboard )is not important to deceive the big ( báo giá tấm cemboard ) or the small, but the deception has been the problem.

    ReplyDelete
  14. Es fácil ganarse una confianza que( tam san be tong sieu nhe ) es fácil de destruir, es ( Sàn panel Đức Lâm ) importante no engañar a los grandes( tấm bê tông siêu nhẹ ) o pequeños, pero el engaño ha sido el problema

    ReplyDelete
  15. Download and install Vidmate App which is the best HD video downloader software available for Android. Get free latest HD movies, songs, and your favorite TV shows.

    ReplyDelete
  16. <a href="https://vidmate.vin/

    ReplyDelete
  17. <a href="https://vidmate.vin/

    ReplyDelete
  18. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Best PHP Training Institute in Chennai|PHP Course in chennai

    Best .Net Training Institute in Chennai
    Big Data Hadoop Training in Chennai
    Linux Training in Chennai
    Cloud Computing Training in Chennai

    ReplyDelete