休眠搜索中的 OnFields 方法接受什么数据类型
What data type does OnFields method in hibernate search accept
我希望能够使用休眠搜索仅搜索用户在表单中选择的字段。
例如,如果用户选择按名字搜索,hibernate 应该只考虑名字。如果用户选择名字和姓氏,hibernate 应该考虑名字和姓氏。
FullTextEntityManager fullTextEntityManager =
org.hibernate.search.jpa.Search.
getFullTextEntityManager(entityManager);
QueryBuilder queryBuilder =
fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity(Client.class).get();
org.apache.lucene.search.Query query =
queryBuilder
.keyword()
.wildcard()
// i want below section (fields) to change based on user input but can't do it with list<string> or collection
.onFields("idNumber", "firstName", "middleName","lastName","nationality")
.matching("*"+searchText.toLowerCase()+"*")
.createQuery();
使用List.toArray
:
List<String> fieldsSelectedByUser = ...;
FullTextEntityManager fullTextEntityManager =
org.hibernate.search.jpa.Search.
getFullTextEntityManager(entityManager);
QueryBuilder queryBuilder =
fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity(Client.class).get();
org.apache.lucene.search.Query query =
queryBuilder
.keyword()
.wildcard()
.onFields(fieldsSelectedByUser.toArray(new String[0]))
.matching("*"+searchText.toLowerCase()+"*")
.createQuery();
我希望能够使用休眠搜索仅搜索用户在表单中选择的字段。
例如,如果用户选择按名字搜索,hibernate 应该只考虑名字。如果用户选择名字和姓氏,hibernate 应该考虑名字和姓氏。
FullTextEntityManager fullTextEntityManager =
org.hibernate.search.jpa.Search.
getFullTextEntityManager(entityManager);
QueryBuilder queryBuilder =
fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity(Client.class).get();
org.apache.lucene.search.Query query =
queryBuilder
.keyword()
.wildcard()
// i want below section (fields) to change based on user input but can't do it with list<string> or collection
.onFields("idNumber", "firstName", "middleName","lastName","nationality")
.matching("*"+searchText.toLowerCase()+"*")
.createQuery();
使用List.toArray
:
List<String> fieldsSelectedByUser = ...;
FullTextEntityManager fullTextEntityManager =
org.hibernate.search.jpa.Search.
getFullTextEntityManager(entityManager);
QueryBuilder queryBuilder =
fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity(Client.class).get();
org.apache.lucene.search.Query query =
queryBuilder
.keyword()
.wildcard()
.onFields(fieldsSelectedByUser.toArray(new String[0]))
.matching("*"+searchText.toLowerCase()+"*")
.createQuery();