看起来您的日期格式适合字典顺序,因此检查一个值是否在两个不同字段之间将遵循类似的模式。Lucene 直到 3.6 版才开始支持StandardQueryParser 中的开放式查询,因此选择足够大的上限和下限来模拟开放式查询:
+EffectiveDate:[0000-01-01 TO value] +ExpirationDate:[value TO 9999-12-31]
我相信,它不能很好地与MultiFieldQueryParser
. 您可能需要通过该解析器运行查询的其余部分,并通过 a 运行类似上述内容StandardQueryParser
并将它们与 a 合并BooleanQuery
。
您也可以手动构建相同的查询,例如:
TermRangeQuery tqlow = new TermRangeQuery("EffectiveDate", null, new BYtesRef(value), true, true);
TermRangeQuery tqlow = new TermRangeQuery("ExpirationDate", new BYtesRef(value), null, true, true);
BooleanQuery betweenQuery = new BooleanQuery();
betweenQuery.add(new BooleanClause(tqlow, BooleanClause.Occur.MUST));
betweenQuery.add(new BooleanClause(tqhigh, BooleanClause.Occur.MUST));
Query parsedQuery = MultiFieldQueryParser.parse............
BooleanQuery rootQuery = new BooleanQuery();
rootQuery.add(new BooleanClause(parsedQuery, BooleanClause.Occur.MUST));
rootQuery.add(new BooleanClause(betweenQuery, BooleanClause.Occur.MUST));