1 回答

TA貢獻1829條經驗 獲得超13個贊
正如錯誤消息所說:
指定的查詢 [...] 包含基于字符串的子查詢,其目標是數字編碼字段“orgId”。
simpleQueryString只能用于定位文本字段。不支持數字字段。
如果您的字符串是通過編程生成的,并且您有一個整數列表,那么您需要執行以下操作:
List<Integer> orgIds = Arrays.asList(1, 3, 8);
BooleanJunction<?> bool = queryBuilder.bool();
for (Integer orgId: orgIds) {
bool.should( queryBuilder.keyword().onField("orgId").matching(orgId).createQuery() );
}
LuceneQuery query = bool.createQuery();
query將匹配字段orgId包含1, 3OR的文檔8。
請參閱https://docs.jboss.org/hibernate/search/5.11/reference/en-US/html_single/#_combining_queries
編輯:如果您需要其他子句,我建議不要在同一個布爾連接中混合“must”和“should”,而是嵌套布爾連接。
例如:
BooleanJunction<?> boolForOrgIds = queryBuilder.bool();
for (Integer orgId: orgIds) {
boolForOrgIds.should(queryBuilder.keyword().onField("orgId").matching(orgId).createQuery());
}
BooleanJunction<?> boolForWholeQuery = queryBuilder.bool();
boolForWholeQuery.must(boolForOrgIds.createQuery());
boolForWholeQuery.must(queryBuilder.keyword().onField("name").matching("anyName").createQuery());
// and add as many "must" as you need
LuceneQuery query = boolForWholeQuery.createQuery();
從技術上講,你可以混合使用“must”和“should”,但效果不會是你所期望的:“should”子句將成為可選的,并且只會在匹配時提高文檔的分數。所以,這不是您需要的。
添加回答
舉報