我想使用休眠搜索在 MySQL 資料庫中的 XML 資料中搜索字串并列印包含該字串的資料的結果串列。
uj5u.com熱心網友回復:
..有效
public List<Object> listFormSubmissionsBySearch(String searchedString) throws InterruptedException {
Session session = sessionFactory.openSession();
EntityManager entityManager = session.getEntityManagerFactory().createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
fullTextEntityManager.createIndexer().startAndWait();
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(FormSubmission.class).get();
org.apache.lucene.search.Query wildcardQuery = queryBuilder
.keyword()
.wildcard()
.onField("data") // name of the field in database
.matching(searchedString)
.createQuery();
List<Object> results = (List<Object>) fullTextEntityManager
.createFullTextQuery(wildcardQuery, FormSubmission.class)
.setProjection(ProjectionConstants.THIS, ProjectionConstants.SCORE)
.getResultList();
// List<Object> flowSubmissions = fullTextEntityManager.createFullTextQuery(wildcardQuery, FlowSubmission.class).getResultList();
return results;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/394529.html
