I use hibernate search on windows.
And I try to configure it, how ever when I create a Query and call the query.list() only got the NULLException at NotSharedReaderProvider.java:43.
I checked and find that the index is not created :(. I don't understand why the code did not work. The codes follows the hibernate search document very well.
anyone can share a successful config on windows?
I config the hibernate.cfg.xml as follows:
<property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>
<property name="hibernate.search.default.indexBase">e:\\test</property>
.....
<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 the java code
public static boolean createIndex() {
Session session = getSession();
FullTextSession fullTextSession = Search.createFullTextSession(session);
try {
List<TBook> bkList = session.createQuery("from TBook").list();
Transaction tx = fullTextSession.beginTransaction();
for (TBook book : bkList) {
fullTextSession.index(book);
}
tx.commit(); // index are written at commit time
fullTextSession.flush();
fullTextSession.close();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
public static List find() {
FullTextSession fullTextSession = this.getFullTextSession();
try {
QueryParser parser = new QueryParser("bkName", new StandardAnalyzer());
org.apache.lucene.search.Query luceneQuery;
luceneQuery = parser.parse("+hibernate +action");
Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery);
return fullTextQuery.list(); //EXCEPTION happends here**************************************************
} catch (ParseException e) {
e.printStackTrace();
} finally {
if (fullTextSession != null) {
fullTextSession.close();
}
}
return null;
}
public static void main(String args[]) {
createIndex();
find();
}
===========================
and the entity class
@Indexed(index="")
public abstract class AbstractTBook implements java.io.Serializable {
.....
// Property accessors
@DocumentId
public Integer getId() {
return this.id;
}
@Field(index=Index.TOKENIZED, store=Store.YES)
public String getBkname() {
return this.bkname;
}
......
}
|