我认为您必须分两步执行此操作:
第 1 步:提取产品 ID
BooleanQuery query = new BooleanQuery();
query.add(new TermQuery("attributeId", 7), BooleanClause.Occur.MUST);
query.add(new TermQuery("value", "hindi"), BooleanClause.Occur.MUST);
TopDocs docs = searcher.search(query, null, searchLimit);
然后,您需要从文档中提取 productId
第 2 步:运行查询
BooleanQuery query = new BooleanQuery();
query.add(new TermQuery("attributeId", 10), BooleanClause.Occur.MUST);
query.add(new TermQuery("value", "Romance"), BooleanClause.Occur.MUST);
// build "IN" clause
BooleanQuery pidQuery = new BooleanQuery();
for( long productId : productIds ){
pidQuery.add(new TermQuery("productId", productId), BooleanClause.Occur.SHOULD);
}
query.add(pidQuery, BooleanClause.Occur.MUST);
TopDocs docs = searcher.search(query, null, searchLimit);