我剛剛創建了一個使用hibernate-search-4.1.1.Final.jar和所有運行時依賴關係的hibernate全文搜索。 這個應用程序沒有錯誤。 但我的Lucene查詢unsing查詢DSL不會返回任何結果。 我的意思是不返回表中的任何行。 任何人都可以幫助我。Hibernate全文搜索
主要搜索程序 此Java代碼用於執行休眠全文搜索。
public class MainSearch {
public static void main(String args[]) {
Iterator iterator;
Session session = HibernateUtil.getSession();
// FullTextSession fullTextSession = Search.getFullTextSession(session);
FullTextSession fullTextSession = Search.getFullTextSession(session);
org.hibernate.Transaction tx = fullTextSession.beginTransaction();
// create native Lucene query unsing the query DSL
// alternatively you can write the Lucene query using the Lucene query
// parser
// or the Lucene programmatic API. The Hibernate Search DSL is
// recommended though
QueryBuilder qb = fullTextSession.getSearchFactory()
.buildQueryBuilder().forEntity(Book.class).get();
org.apache.lucene.search.Query query = qb.keyword()
.onFields("title", "subtitle", "authors.name").matching("cpp")
.createQuery();
// wrap Lucene query in a org.hibernate.Query
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(
query, Book.class);
// execute search
List result = hibQuery.list();
iterator = result.iterator();
while (iterator.hasNext()) {
System.out.print(iterator.next() + " ");
}
System.out.println();
// Check list empty or not
if (result.isEmpty()) {
System.out.println("Linked list is empty");
}
tx.commit();
session.close();
}
}
http://stackoverflow.com/questions/9488094/ hibernate-mssql-fulltext-search-via-contains 解決同樣的問題 – user1817599 2013-01-13 22:13:56