<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>boolean &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/boolean-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://solr.pl/en/</link>
	<description>All things to be found - Blog related to Apache Solr &#38; Lucene projects - https://solr.apache.org</description>
	<lastBuildDate>Wed, 11 Nov 2020 20:56:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Do I have to look for maxBooleanClauses when using filters ?</title>
		<link>https://solr.pl/en/2011/12/19/do-i-have-to-look-for-maxbooleanclauses-when-using-filters/</link>
					<comments>https://solr.pl/en/2011/12/19/do-i-have-to-look-for-maxbooleanclauses-when-using-filters/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 19 Dec 2011 20:56:29 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[bool]]></category>
		<category><![CDATA[boolean]]></category>
		<category><![CDATA[clause]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[maxBooleanClauses]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[solr]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=388</guid>

					<description><![CDATA[One of the configuration variables we can find in the solrconfig.xml file is&#160;maxBooleanClauses, which specifies the maximum number of boolean clauses that can be combined in a single query. The question is, do I have to worry about it when]]></description>
										<content:encoded><![CDATA[<p>One of the configuration variables we can find in the <em>solrconfig.xml</em> file is&nbsp;<em>maxBooleanClauses</em>, which specifies the maximum number of boolean clauses that can be combined in a single query. The question is, do I have to worry about it when using filters in Solr ? Let&#8217;s try to answer that question without getting into Lucene and Solr source code.</p>
<p><span id="more-388"></span></p>
<h3>Query</h3>
<p>Let&#8217;s assume that we have the following query we want to change:
</p>
<pre class="brush:xml">q=category:1 AND category:2 AND category:3 ... AND category:2000</pre>
<p>Sending such a query to the Solr instance with the default configuration would result in the following exception: &#8220;<em>too many boolean clauses</em>&#8220;. Of course we could modify the <em>maxBooleanClauses</em> variable in <em>solrconfig.xml</em> file and get rid of the exception, but let&#8217;s try do it the other way:</p>
<h3>Let&#8217;s change the query to use filters</h3>
<p>So, we change the above query to use filters &#8211; the <em>fq</em> parameter<em></em>:
</p>
<pre class="brush:xml">q=*:*&amp;fq=category:(1 2 3 ... 2000)</pre>
<p>We send the query to Solr and &#8230; and again the same situation happens &#8211; exception with the &#8220;<em>too many boolean clauses</em>&#8221; message. It happens because Solr has to &#8220;calculate&#8221; filter content and thus run the appropriate query. So, let&#8217;s modify the query once again:</p>
<h3>Final query change</h3>
<p>After the final modification our query should look like this:
</p>
<pre class="brush:xml">q=*:*&amp;fq=category:1&amp;fq=category:2&amp;fq=category:3&amp;....&amp;fq=category:2000</pre>
<p>After sending such a query we will get the search results (of course if there are documents matching the query in the index). This time Solr didn&#8217;t have to run a single, large boolean query and that&#8217;s why we didn&#8217;t exceed the<em> maxBooleanClauses</em> limit.</p>
<h3>To sum up</h3>
<p>As you can see the answer to the question asked in the begining of the post depend on the query we want to run. If our query is using <em>AND</em> boolean operator we can use <em>fq</em> parameter because multiple <em>fq</em> parameters are concatenated using <em>AND</em>. However if we have to use <em>OR</em> we would have to change the limit defined by <em>maxBooleanClauses</em> configuration variable. But please remember that changing this limit can have a negative effect on performance and memory usage.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2011/12/19/do-i-have-to-look-for-maxbooleanclauses-when-using-filters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
