[英]Provide a List of values as search Criteria in Hibernate Search
I have the implemented Hibernate search and it works fine. 我已经实现了Hibernate搜索,并且工作正常。
So if i say want to get all employees matching Captain ,i use the following code 因此,如果我说想让所有与队长匹配的员工使用以下代码
QueryBuilder qb = fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity(Employee.class).get();
org.apache.lucene.search.Query query = qb.keyword().onFields("name")
.matching("Captain").createQuery();
// wrap Lucene query in a javax.persistence.Query
javax.persistence.Query persistenceQuery = fullTextEntityManager
.createFullTextQuery(query, Employee.class);
// execute search
List<Employee> result = persistenceQuery.getResultList();
System.out.println("num of employess:" + result);
My question is if i want to pass a list of values as search criteria,does hibernate search provide any method to do that. 我的问题是,如果我想通过值列表作为搜索条件,休眠搜索是否提供任何方法来做到这一点。
For example if i want to get employees from a table whose names are similar to either one in the following list [Abhi,Juhi,Joan,Paul,James] 例如,如果我想从一个名称与以下列表中的任一个相似的表中获取员工,则该表类似于[阿比,朱希,琼,保罗,詹姆斯]
To search for multiple possible words in the same field, simply add them all in the matching clause. 要在同一字段中搜索多个可能的单词,只需将它们全部添加到匹配子句中。
//search document with storm or lightning in their history
Query luceneQuery =
mythQB.keyword().onField("history").matching("storm lightning").createQuery();
Check documentation 检查文件
http://docs.jboss.org/hibernate/search/4.1/reference/en-US/html/search-query.html http://docs.jboss.org/hibernate/search/4.1/reference/zh-CN/html/search-query.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.