我正在开发一个Spring 3.2 webapp。我希望有人不能帮助我。
我尝试在“站点”数据库表的“名称”字段中获取所有带有“test”字样的站点。
网站表格行:
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。
问题是这个方法总是返回null List。
答案 0 :(得分:1)
问题解决了,我不得不在lucene查询之前调用createIndexer()。startAndWait()。
http://docs.jboss.org/hibernate/search/4.4/reference/en-US/html_single/#d0e396