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() ?