-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Lucene integration, how to access RamDirectory from Outside
PostPosted: Wed Aug 23, 2006 7:09 am 
Newbie

Joined: Thu Feb 12, 2004 7:53 pm
Posts: 2
Hibernate version: svn head (r10305)

Assume the following sessionfactory using the Spring Framework:

Code:
     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
       <property name="dataSource" ref="dataSource"/>
       <property name="annotatedClasses">
         <list>
                           <!-- list of annotation mapped classes-->
           </list>
         </property>
       <property name="hibernateProperties">
            <props>
               <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
               <prop key="hibernate.lucene.default.directory_provider">org.hibernate.lucene.store.RAMDirectoryProvider</prop>
            </props>
       </property>
       <property name="eventListeners">
          <map>
             <entry key="post-commit-update" value-ref="luceneListener"/>
             <entry key="post-commit-insert" value-ref="luceneListener"/>
             <entry key="post-commit-delete" value-ref="luceneListener"/>
          </map>
       </property>
     </bean>
     
     <bean id="luceneListener" class="org.hibernate.lucene.event.LuceneEventListener"/>

When performing CRUD operations on the mapped classes, the logs show that they get indexed correctly. How can I access the lucene index directory (RamDirectory in this case) in order to run searches? In the current API I can't see any way to do this.
My idea is to add a methode "public Directory getDirectory(Class)" to LuceneEventListener. The searcher code might then use
Code:
LuceneEventListener listener = .... // get e.g. from Spring's applicationContext
Directory dir = listener.getDirectory(Car.class);
Searcher searcher = new IndexSearcher(dir);      
QueryParser qp = new QueryParser("Manufacturer", new StandardAnalyzer());
Hits hits = searcher.search(qp.parse("mercedes"));

Do you have a different way to get the Directory? If desired, I'll create a patch for my approach.

In general, I do not completly understand the DirectoryProviderFactory. Since I'm fairly new to Lucene, the following might be complete pribble-prabble, so be warned ;-)
Assume two classes sharing the same index name:
Code:
@Indexed(index="common")
class a { ...}
@Indexed(index="common")
class b {...}

If RAM based directory is used, these to classes will get different two different Lucene RAMDirectories. So a search in the one will not find entries of the other and vice versa. The same applies for FS based: two FSDirectory instances access the same path concurrently causing index file being overwritten.

Regards,
Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 12:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Have a look at http://anonhibernate.labs.jboss.com/bra ... tegration/

there is a nice querying facility for the Lucene index. Feedbacks very welcome

_________________
Emmanuel


Top
 Profile  
 
 Post subject: having problems registering listeners
PostPosted: Thu Feb 08, 2007 5:22 pm 
Newbie

Joined: Thu Feb 08, 2007 5:10 pm
Posts: 4
According to the document here:
http://www.hibernate.org/hib_docs/annot ... ucene.html

the listener is registered in hibernate.cfg.xml
Code:
<hibernate-configuration>
    ...
    <event type="post-update"
        <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
    </event>
    <event type="post-insert"
        <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
    </event>
    <event type="post-delete"
        <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
    </event>
</hibernate-configuration>


and i converted this into spring's config file as:

Code:
  <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="hibernateProperties">
      <value>
        hibernate.dialect=org.hibernate.dialect.HSQLDialect
      </value>
    </property>
    <property name="eventListeners">
       <map>
          <entry key="post-update">
             <bean class="org.hibernate.search.event.FullTextIndexEventListener" />
          </entry>
                ...
       </map>
    </property>
  </bean>



but i got this exception

Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [test-servlet.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.cfg.Configuration
Caused by: java.lang.ClassCastException: org.hibernate.cfg.Configuration
   at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:82)
   at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:356)
   at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1304)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:804)
   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:744)
   at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:131)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1118)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
   at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:182)
   at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:152)
   at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105)
   at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:83)
   at junit.framework.TestCase.runBare(TestCase.java:125)
   at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)




Looking at the top post where org.hibernate.lucene.event.LuceneEventListener is used instead of org.hibernate.search.event.FullTextIndexEventListener

but i could not locate org.hibernate.lucene.event.LuceneEventListener inside of HAN 3.2.1

any ideas of what am i doing wrong here?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 9:44 am 
Newbie

Joined: Fri Feb 09, 2007 9:02 am
Posts: 1
I am trying to get it work as well and would be interested in any solutions. I do not get any exceptions on start-up though when using this setup:
...
<property name="eventListeners">
<map>
<entry>
<key>
<value>post-update</value>
</key>
<ref bean="FullTextIndexEventListener"/>
</entry>
<entry>
<key>
<value>post-insert</value>
</key>
<ref bean="FullTextIndexEventListener"/>
</entry>
<entry>
<key>
<value>post-delete</value>
</key>
<ref bean="FullTextIndexEventListener"/>
</entry>
</map>
</property>
..

<bean id="FullTextIndexEventListener" class="org.hibernate.search.event.FullTextIndexEventListener"/>

But no indexes are created when I am inserting entity objects. If it works for you, could you post your entity annotations and query?


Top
 Profile  
 
 Post subject: Re: having problems registering listeners
PostPosted: Fri Feb 09, 2007 3:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hr, you somehow needs to ask Spring to use an AnnotationConfiguration rather than a regular configuration.

It is mandatory to benefic Hibernate Annotations anyway.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 3:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
torsty,
either your class are not annotated with @Indexed or Spring does not set up the event listener properly. Seems ;ore complex than the actual hibernate configuration.

I'll try to come up with auto event wiring for Hibernate Annotations 3.3

_________________
Emmanuel


Top
 Profile  
 
 Post subject: how to specify a different analyzer in Spring
PostPosted: Mon Feb 12, 2007 10:03 pm 
Newbie

Joined: Thu Feb 08, 2007 5:10 pm
Posts: 4
thanks! I finally got it to work.

But just come to a problem where we would like to specify a SnowBallAnalyzer instead of the default StandardAnalyzer for indexing in the spring config file.

How can we do it? cheers ....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 7:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
the current solution is to define the hibernate.search.analyzer property (I don't know the Spring syntax)

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.