Reputation: 4111
I am development one Spring 3.2 webapp. I am hoping to somebody cant help me with this.
I try get all Sites with "test" word in "name" field in "Site" db table.
Site Table row:
id: 1 name: "test" ...
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 class
@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() is the Session returned by SessionFactory Spring bean.
Question is this method allways return null List.
Upvotes: 0
Views: 474
Reputation: 4111
Problem solved, I had to call createIndexer().startAndWait() before lucene query.
http://docs.jboss.org/hibernate/search/4.4/reference/en-US/html_single/#d0e396
Upvotes: 1