-->
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.  [ 3 posts ] 
Author Message
 Post subject: [Hibernate Search] Indexing
PostPosted: Mon May 07, 2007 8:22 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hello,

I'm still learning how to make Hibernate Search work.

First, I want to know how I must use FullTextSession.index because I believed that there was an automatic indexing.

This is a part of my cfg.xml :
Code:
        <property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>
        <property name="hibernate.search.default.indexBase">/home/fmn/templucene/test</property>

        <mapping resource="servicedonnees/Mapping.hbm.xml" />

      <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>


And my code is :
Code:
      Session s = HibernateUtil.getCurrentSession();
      FullTextSession fullTextSession = Search.createFullTextSession(s);   

      Video video1 = new Video("titre 1", 30);
      Video video2 = new Video("titre 2", 50);
      Video video3 = new Video("titre 8", 60);
      
      s.persist(video1);
      s.persist(video2);
      s.persist(video3);
      
      fullTextSession.index(video1);
      fullTextSession.index(video2);
      fullTextSession.index(video3);
      
      QueryParser parser = new QueryParser("title", new StopAnalyzer() );

      org.apache.lucene.search.Query luceneQuery = null;
      try {
         luceneQuery = parser.parse("titre:t*");
      } catch (ParseException e) {
         e.printStackTrace();
      }
      org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery);

      List result = (fullTextQuery).list(); //return a list of managed objects
      Iterator i = result.iterator();
      while(i.hasNext())
      {
         System.out.println("Res : "+i.next());
      }


It works, but is it possible not to use index() ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 8:35 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I answer to my question : I forgot to open a transaction and then to commit :

Code:
      Transaction tx = s.beginTransaction();

      Video video1 = new Video("titre 1", 30);
      Video video2 = new Video("titre 2", 50);
      Video video3 = new Video("titre 8", 60);
      
      s.persist(video1);
      s.persist(video2);
      s.persist(video3);

      tx.commit();


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 11:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
just to clarify, this is not required to manually call index, that would be lame ;-)

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.