Ed.*_*Ed. 16 lucene lucene.net
我有两组搜索索引.TestIndex(在我们的测试环境中使用)和ProdIndex(在PRODUCTION环境中使用).Lucene搜索查询:+ date:[20090410184806 TO 20091007184806]适用于测试索引,但为Prod索引提供此错误消息.
"maxClauseCount设置为1024"
如果我在执行搜索查询之前执行以下行,那么我不会收到此错误.BooleanQuery.SetMaxClauseCount(Int16.MaxValue); searcher.Search(myQuery,collector);
我在这里错过了什么吗?为什么没有在测试索引中出现这个错误?两个索引的模式是相同的.它们只与记录/数据的数量有所不同.PROD索引的记录数量(大约1300)比测试中的更多(大约950) .
Sha*_*ore 12
范围查询实质上被转换为布尔查询,每个可能的值都有一个子句,或者一起进行OR运算.
例如,查询+价格:[10到13]转换为布尔查询
+(price:10 price:11 price:12 price:13)
Run Code Online (Sandbox Code Playgroud)
假设索引中存在所有值10-13.
我想,你所有的1300个值都落在你给出的范围内.因此,布尔查询有1300个子句,高于默认值1024.在测试索引中,没有达到1024的限制,因为只有950个值.
Ran*_*uer 12
我有同样的问题.我的解决方案是捕获BooleanQuery.TooManyClauses并动态增加maxClauseCount.
这里有一些类似于我在生产中的代码.
好运,兰迪
private static Hits searchIndex(Searcher searcher, Query query)
throws IOException
{
boolean retry = true;
while (retry)
{
try
{
retry = false;
Hits myHits = searcher.search(query);
return myHits;
}
catch (BooleanQuery.TooManyClauses e)
{
// Double the number of boolean queries allowed.
// The default is in org.apache.lucene.search.BooleanQuery and is 1024.
String defaultQueries = Integer.toString(BooleanQuery.getMaxClauseCount());
int oldQueries = Integer.parseInt(System.getProperty("org.apache.lucene.maxClauseCount", defaultQueries));
int newQueries = oldQueries * 2;
log.error("Too many hits for query: " + oldQueries + ". Increasing to " + newQueries, e);
System.setProperty("org.apache.lucene.maxClauseCount", Integer.toString(newQueries));
BooleanQuery.setMaxClauseCount(newQueries);
retry = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20894 次 |
| 最近记录: |