找出maxClauseCount的原因设置为1024错误

问题描述 投票:16回答:5

我有两组搜索索引。 TestIndex(在我们的测试环境中使用)和ProdIndex(在PRODUCTION环境中使用)。 Lucene搜索查询:+ date:[20090410184806 TO 20091007184806]适用于测试索引,但为Prod索引提供此错误消息。

“maxClauseCount设置为1024”

如果我在执行搜索查询之前执行以下行,那么我不会收到此错误。 BooleanQuery.SetMaxClauseCount(Int16.MaxValue); searcher.Search(myQuery,collector);

我在这里错过了什么吗?为什么没有在测试索引中出现这个错误?两个索引的模式是相同的。它们只与记录/数据的数量有所不同.PROD索引的记录数量(大约1300)比测试中的更多(大约950) 。

lucene lucene.net
5个回答
12
投票

范围查询实质上被转换为布尔查询,每个可能的值都有一个子句,或者一起进行OR运算。

例如,查询+价格:[10到13]被转换为布尔查询

+(price:10 price:11 price:12 price:13)

假设索引中存在所有值10-13。

我想,你所有的1300个值都落在你给出的范围内。因此,布尔查询有1300个子句,高于默认值1024.在测试索引中,没有达到1024的限制,因为只有950个值。


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;
            }
        }
    }

1
投票

我在使用Sitecore Web内容管理系统运行的C#代码中遇到了同样的问题。我上面使用了Randy的答案,但是无法使用System get和set属性功能。相反,我检索了当前计数,增加了它,并将其设置回来。工作得很好!

catch (BooleanQuery.TooManyClauses e)
{
    // Increment the number of boolean queries allowed.
    // The default is 1024.
    var currMaxClause = BooleanQuery.GetMaxClauseCount();
    var newMaxClause = currMaxClause + 1024;
    BooleanQuery.SetMaxClauseCount(newMaxClause);
    retry = true;
}

1
投票

添加此代码

@using Lucene.Net.Search;
@BooleanQuery.SetMaxClauseCount(2048);

0
投票

就这么说,BooleanQuery.setMaxClauseCount( Integer.MAX_VALUE );and就是这样。

© www.soinside.com 2019 - 2024. All rights reserved.