我正在从事 Spring 和 Hibernate 项目,并且正在使用 Hibernate Lucene Search。它搜索得很好,但是在显示结果时它会像这样显示(即,如果我搜索标题)
[id: 10 | title:easylib, id: 11 | title:IBM, id: 12 | title:Wipro]
但我想要的是它应该只显示'Wipro',而不是它的 id 或其他东西
这是我的代码(在标题的 POJO 类中):
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
@Column(name = "title", nullable = false, length = 150)
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
这是在我的 DAO 课程中
private void doIndex() throws InterruptedException {
Session session = getSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
fullTextSession.createIndexer().startAndWait();
}
private List<CatalogueBase> searchTitle(String queryString) {
Session session = getSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(CatalogueBase.class).get();
org.apache.lucene.search.Query luceneQuery = queryBuilder.keyword().onFields("subTitle","publishedplace","title").matching(queryString).createQuery();
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, CatalogueBase.class);
List<CatalogueBase> contactList = fullTextQuery.list();
return contactList;
}
@Override
public List<CatalogueBase> getSearchDao(String search) throws InterruptedException {
doIndex();
List<CatalogueBase> result = searchTitle(search);
return result;
}