2013-11-04 26 views
0

我正在開發一個Spring 3.2 webapp。我希望有人不能幫助我。在Spring Web上使用Lucene進行Hibernate搜索

我嘗試在「網站」數據庫表中的「名稱」字段中獲取帶有「測試」字的所有網站。

網站錶行:

ID:1 名稱: 「測試」 ...

Site.class

@Entity 
@Indexed 
@Spatial 
@Table(name = "site") 
public class Site implements Serializable { 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @Column(name = "id") 
    private int id; 
    @NotNull 
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO) 
    private String name; 

... 
} 

DAO類

@Override 
public List<Site> getSite(String word) { 

    //word = "test" at this point on debug. 

    QueryBuilder builder = Search.getFullTextSession(this.getCurrentSession()).getSearchFactory() 
      .buildQueryBuilder().forEntity(Site.class).get(); 

    org.apache.lucene.search.Query luceneQuery = builder.keyword().onField("name").matching(word).createQuery(); 

    org.hibernate.Query hibQuery = Search.getFullTextSession(this.getCurrentSession()).createFullTextQuery(luceneQuery, Site.class); 

    return hibQuery.list(); 
} 

的getCurrentSession( )是由SessionFactory Spring bean返回的Session。

問題是這種方法allways返回空列表。

回答