<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technotrance, Illusions and Perspectives &#187; hibernate-search</title>
	<atom:link href="http://myblog.shriharisc.com/tag/hibernate-search/feed/" rel="self" type="application/rss+xml" />
	<link>http://myblog.shriharisc.com</link>
	<description>A dose of everyday bruises with Java/JEE</description>
	<lastBuildDate>Mon, 12 Jul 2010 17:55:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Integrating Hibernate Search on PrimeFaces using Google Guice and JBoss Seam</title>
		<link>http://myblog.shriharisc.com/2009/11/14/integrating-hibernate-search-on-primefaces-using-google-guice-and-jboss-seam/</link>
		<comments>http://myblog.shriharisc.com/2009/11/14/integrating-hibernate-search-on-primefaces-using-google-guice-and-jboss-seam/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 18:58:27 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[jee-light]]></category>
		<category><![CDATA[google-guice]]></category>
		<category><![CDATA[hibernate-search]]></category>
		<category><![CDATA[jboss-seam]]></category>
		<category><![CDATA[primefaces]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=133</guid>
		<description><![CDATA[Recently I have been working on an application involving PrimeFaces and required search capabilities directly on the persisted data. Though I can use Hibernate search for implementing search services, the Google Guice, the underlying IoC framework, which PrimeFaces provide does not provide me the out-of-the-box integration. I am extending from my previous blog post which [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have been working on an application involving <a href="http://primefaces.prime.com.tr/en/">PrimeFaces</a> and required search capabilities directly on the persisted data. Though I can use Hibernate search for implementing search services, the Google Guice, the underlying IoC framework, which PrimeFaces provide does not provide me the out-of-the-box integration. I am extending from my <a href="http://myblog.shriharisc.com/2009/07/31/injecting-entitymanager-in-google-guice-through-jboss-seam/">previous blog post</a> which talked about using Google Guice to inject JPA EntityManager. This post builds on the previous post and explores the option of search. Here are the following sequence of steps I followed to ensure PrimeFaces widgets are Hibernate Search compliant:</p>
<p>1)  Follow the steps mentioned to get an EntityManager instance fro m JBoss Seam&#8217;s component xml and register in the Google Guice injector using a Provider  implementation. Make a little change where the Provider&#8217;s getter method is made static.  Following is the EntityManagerProvider code snippet to do that:</p>
<pre class="brush: java">
class EntityManagerProvider implements Provider
{       static EntityManagerFactory entityManagerFactory = null;
        public static EntityManager get()
        {   return entityManagerFactory.createEntityManager();
        }
}
</pre>
<p>2) Implement Guice injection Provider for constructing a FullTextEntityManager from EntityManager</p>
<pre class="brush: java">
public class FullTextEntityManagerProvider implements Provider
{    static FullTextEntityManager fullTextManager = null;
     private static EntityManager entityManager;

     public static void setEntityManager(EntityManager em)
     {   entityManager = em;
     }

      public FullTextEntityManager get()
      {   if(fullTextManager==null)
             fullTextManager = Search.getFullTextEntityManager(entityManager);
           return fullTextManager;
      }
}
</pre>
<p>3) Modify the custom module (now refactored as MySearchEntityManagerModule) to construct the FullTextEntityManager using EntityManager instance as shown below.</p>
<pre class="brush: java">
public class MySearchEntityManagerModule extends AbstractModule
{      public void configure()
       {   Expressions expressions = Expressions.instance();
           ValueExpression emfVE = expressions.createValueExpression(&quot;#{my_persistence_unit}&quot;);
           EntityManagerFactory emf = (EntityManagerFactory)emfVE.getValue();
           EntityManagerProvider.setEntityManagerFactory(emf);
           FullTextEntityManagerProvider.setEntityManager(provider.get());

            //bind EntityManager and FullTextEntityManager for both pure database and search specific integration
            bind(EntityManager.class).toProvider(EntityManagerProvider.class).in(Scopes.SINGLETON);
            bind(FullTextEntityManager.class).toProvider(FullTextEntityManagerProvider.class).in(Scopes.SINGLETON);
     }
}
</pre>
<p>3) Inject the FullTextEntityManager in the dataservice (DAO) for searching for text tokens using Hibernate Search.</p>
<pre class="brush: java">
@Name(&quot;hybrid&quot;)
@Guice
public class HybridDAO
{  @Inject FullTextEntityManager searchManager;
    //other DAO methods to perform search using Hibernate Search and Lucene
}
</pre>
<p>This quick tip provides us a capability of enhancing Primefaces widgets to use the power of Hibernate Search for search and much more extensible features.</p>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/11/14/integrating-hibernate-search-on-primefaces-using-google-guice-and-jboss-seam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
