<?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>facet &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/facet-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>Tue, 10 Nov 2020 13:18:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<item>
		<title>Hierarchical faceting &#8211; Pivot facets in trunk</title>
		<link>https://solr.pl/en/2010/10/25/hierarchical-faceting-pivot-facets-in-trunk/</link>
					<comments>https://solr.pl/en/2010/10/25/hierarchical-faceting-pivot-facets-in-trunk/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 25 Oct 2010 12:17:29 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[4.0]]></category>
		<category><![CDATA[facet]]></category>
		<category><![CDATA[grouping]]></category>
		<category><![CDATA[hierarchical]]></category>
		<category><![CDATA[pivot]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[trunk]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=90</guid>

					<description><![CDATA[In a large number of implementations which I took part in, sooner or later, the question arise &#8211; what can we do to get faceting as a tree structure. Of course there some tricks for that, however, their use was]]></description>
										<content:encoded><![CDATA[<p>In  a large number of implementations which I took part in, sooner or  later, the question arise &#8211; what can we do to get faceting as a tree  structure. Of  course there some tricks for that, however, their use was to modify the  data and appropriate processing of the results on application side. It was not particularly functional, nor especially comfortable. However,  a few days ago Solr version 4.0 has been enhanced with code that is  marked as <a href="https://issues.apache.org/jira/browse/SOLR-792" target="_blank" rel="noopener noreferrer">Solr-792</a> in the system JIRA. Let&#8217;s see in this case, how to  get the faceting results as a tree.</p>
<p><span id="more-90"></span></p>
<p>Important Note &#8211; at this point this functionality is only available in version 4.0, Solr, which is the development version. To use this version you need to download the code from trunk of Lucene/Solr SVN repository.</p>
<h3>A few words at the beginning</h3>
<p>In many projects in which I had the opportunity to deal with there was a need to use a hierarchical faceting. One  of the simplest example is the requirement of showing the cities in the  provinces and the number of documents in both provinces, as well as in  various cities. Till recently, with no changes in the structure of data, it was impossible to achieve such functionality. Now it is possible <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h3>Indexing</h3>
<p>In  order not to unnecessarily complicate the described functionality I  decided to use the sample XML documents that are available in the  directory <em>/exampledocs</em> of the example deployment. I also didn&#8217;t modify the<em> schema.xml </em>file, or <em>solrconfig.xml</em>, so that configurations are standard. So thats all when it comes to configuration. So we can start the indexing process (I called the command from the directory <em>$SOLR_HOME/exampledocs/</em>):
</p>
<pre class="brush:bash">./post.sh *.xml</pre>
<p>After seeing several screens of information, and we have our data indexed.</p>
<h3>The mechanism</h3>
<p>It is not difficult to use hierarchical faceting. Solr creators gave us to use two additional parameters to the ones we already know:</p>
<ul>
<li> <em>facet.pivot</em> &#8211; list of comma-separated fields, which shows at which fields and in what order to calculate the structure,</li>
<li><em>facet.pivot.mincount</em> &#8211; the minimum number of documents there needs to be  to the result to be included in faceting results. The default value is 1.</li>
</ul>
<p>So let&#8217;s try it.</p>
<h3>Queries</h3>
<p>At the beginning of the try with two fields. I  query for all the documents from the index and add the parameter  facet.pivot=cat,inStock to say Solr that I want to get the results of  the hierarchical faceting, where the first level of the hierarchy is the  cat field, and the second level is the inStock field. The query looks as follows:
</p>
<pre class="brush:xml">http://localhost:8983/solr/select/?q=*:*&amp;facet=true&amp;facet.pivot=cat,inStock</pre>
<p>To shorten the listing I omitted the part responsible for the search results along with a header.
</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;response&gt;
.
.
.
&lt;result name="response" numFound="19" start="0"/&gt;
&lt;lst name="facet_counts"&gt;
  &lt;lst name="facet_queries"/&gt;
  &lt;lst name="facet_fields"/&gt;
  &lt;lst name="facet_dates"/&gt;
  &lt;lst name="facet_ranges"/&gt;
  &lt;lst name="facet_pivot"&gt;
    &lt;arr name="cat,inStock"&gt;
      &lt;lst&gt;
        &lt;str name="field"&gt;cat&lt;/str&gt;
        &lt;str name="value"&gt;electronics&lt;/str&gt;
        &lt;int name="count"&gt;17&lt;/int&gt;
        &lt;arr name="pivot"&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;true&lt;/bool&gt;
            &lt;int name="count"&gt;13&lt;/int&gt;
          &lt;/lst&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;false&lt;/bool&gt;
            &lt;int name="count"&gt;4&lt;/int&gt;
          &lt;/lst&gt;
        &lt;/arr&gt;
      &lt;/lst&gt;
      &lt;lst&gt;
        &lt;str name="field"&gt;cat&lt;/str&gt;
        &lt;str name="value"&gt;memory&lt;/str&gt;
        &lt;int name="count"&gt;6&lt;/int&gt;
        &lt;arr name="pivot"&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;true&lt;/bool&gt;
            &lt;int name="count"&gt;6&lt;/int&gt;
          &lt;/lst&gt;
        &lt;/arr&gt;
      &lt;/lst&gt;
      &lt;lst&gt;
        &lt;str name="field"&gt;cat&lt;/str&gt;
        &lt;str name="value"&gt;connector&lt;/str&gt;
        &lt;int name="count"&gt;2&lt;/int&gt;
        &lt;arr name="pivot"&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;false&lt;/bool&gt;
            &lt;int name="count"&gt;2&lt;/int&gt;
          &lt;/lst&gt;
        &lt;/arr&gt;
      &lt;/lst&gt;
      &lt;lst&gt;
        &lt;str name="field"&gt;cat&lt;/str&gt;
        &lt;str name="value"&gt;graphics card&lt;/str&gt;
        &lt;int name="count"&gt;2&lt;/int&gt;
        &lt;arr name="pivot"&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;false&lt;/bool&gt;
            &lt;int name="count"&gt;2&lt;/int&gt;
          &lt;/lst&gt;
        &lt;/arr&gt;
      &lt;/lst&gt;
      &lt;lst&gt;
        &lt;str name="field"&gt;cat&lt;/str&gt;
        &lt;str name="value"&gt;hard drive&lt;/str&gt;
        &lt;int name="count"&gt;2&lt;/int&gt;
        &lt;arr name="pivot"&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;true&lt;/bool&gt;
            &lt;int name="count"&gt;2&lt;/int&gt;
          &lt;/lst&gt;
        &lt;/arr&gt;
      &lt;/lst&gt;
      &lt;lst&gt;
        &lt;str name="field"&gt;cat&lt;/str&gt;
        &lt;str name="value"&gt;monitor&lt;/str&gt;
        &lt;int name="count"&gt;2&lt;/int&gt;
        &lt;arr name="pivot"&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;true&lt;/bool&gt;
            &lt;int name="count"&gt;2&lt;/int&gt;
          &lt;/lst&gt;
        &lt;/arr&gt;
      &lt;/lst&gt;
      &lt;lst&gt;
        &lt;str name="field"&gt;cat&lt;/str&gt;
        &lt;str name="value"&gt;search&lt;/str&gt;
        &lt;int name="count"&gt;2&lt;/int&gt;
        &lt;arr name="pivot"&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;true&lt;/bool&gt;
            &lt;int name="count"&gt;2&lt;/int&gt;
          &lt;/lst&gt;
        &lt;/arr&gt;
      &lt;/lst&gt;
      &lt;lst&gt;
        &lt;str name="field"&gt;cat&lt;/str&gt;
        &lt;str name="value"&gt;software&lt;/str&gt;
        &lt;int name="count"&gt;2&lt;/int&gt;
        &lt;arr name="pivot"&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;true&lt;/bool&gt;
            &lt;int name="count"&gt;2&lt;/int&gt;
          &lt;/lst&gt;
        &lt;/arr&gt;
      &lt;/lst&gt;
    &lt;/arr&gt;
  &lt;/lst&gt;
&lt;/lst&gt;
&lt;/response&gt;</pre>
<p>The presentation of faceting results has changed in this case. For  each of the main level we have the markers defining the field (the tag  with the attribute <em>name=&#8221;field&#8221;</em>), value (the tag with the attribute <em> name=&#8221;value&#8221;</em>) and the number of documents (the tag with the attribute  <em>name=&#8221;count&#8221;</em>). Next there is the the second level hierarchy (tag with the attribute <em>name=&#8221;pivot&#8221;</em>). The second level contains the same elements as the first level &#8211; name, value and the number of documents with a given value.</p>
<p>Let&#8217;s see how this mechanism can deal with more levels of depth. To check that I run the following query:
</p>
<pre class="brush:xml">http://localhost:8983/solr/select/?q=*:*&amp;facet=true&amp;facet.pivot=cat,inStock,features</pre>
<p>I omitted the response header with the results, leaving the faceting results only.  In addition, due to the length of the faceting results I only show one level one level faceting:
</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;response&gt;
.
.
.
&lt;result name="response" numFound="19" start="0"/&gt;
&lt;lst name="facet_counts"&gt;
  &lt;lst name="facet_queries"/&gt;
  &lt;lst name="facet_fields"/&gt;
  &lt;lst name="facet_dates"/&gt;
  &lt;lst name="facet_ranges"/&gt;
  &lt;lst name="facet_pivot"&gt;
    &lt;arr name="cat,inStock,features"&gt;
      &lt;lst&gt;
        &lt;str name="field"&gt;cat&lt;/str&gt;
        &lt;str name="value"&gt;electronics&lt;/str&gt;
        &lt;int name="count"&gt;17&lt;/int&gt;
        &lt;arr name="pivot"&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;true&lt;/bool&gt;
            &lt;int name="count"&gt;13&lt;/int&gt;
            &lt;arr name="pivot"&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;2&lt;/str&gt;
                &lt;int name="count"&gt;7&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;3&lt;/str&gt;
                &lt;int name="count"&gt;7&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;lcd&lt;/str&gt;
                &lt;int name="count"&gt;5&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;x&lt;/str&gt;
                &lt;int name="count"&gt;5&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;ca&lt;/str&gt;
                &lt;int name="count"&gt;4&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;latenc&lt;/str&gt;
                &lt;int name="count"&gt;4&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;tft&lt;/str&gt;
                &lt;int name="count"&gt;4&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;v&lt;/str&gt;
                &lt;int name="count"&gt;4&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;0&lt;/str&gt;
                &lt;int name="count"&gt;3&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;1&lt;/str&gt;
                &lt;int name="count"&gt;3&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;25&lt;/str&gt;
                &lt;int name="count"&gt;3&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;30&lt;/str&gt;
                &lt;int name="count"&gt;3&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;5&lt;/str&gt;
                &lt;int name="count"&gt;3&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;7&lt;/str&gt;
                &lt;int name="count"&gt;3&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;8&lt;/str&gt;
                &lt;int name="count"&gt;3&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;time&lt;/str&gt;
                &lt;int name="count"&gt;3&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;up&lt;/str&gt;
                &lt;int name="count"&gt;3&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;000&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;19&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;20&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;2336&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;27&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;275&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;6&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;75&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;activ&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;built&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;cach&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;color&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;flash&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;heat&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;heatspread&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;matrix&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;mb&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;ms&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;photo&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;resolut&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;seek&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;speed&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;spreader&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;unbuff&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;usb&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
            &lt;/arr&gt;
          &lt;/lst&gt;
          &lt;lst&gt;
            &lt;str name="field"&gt;inStock&lt;/str&gt;
            &lt;bool name="value"&gt;false&lt;/bool&gt;
            &lt;int name="count"&gt;4&lt;/int&gt;
            &lt;arr name="pivot"&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;0&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;1&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;16&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;2&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;20&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;3&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;9&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;90&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;adapt&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;car&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;clock&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;direct&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;directx&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;dual&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;dvi&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;express&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;gddr&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;ghz&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;gl&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;gpu&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;gpuvpu&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;hdtv&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;mb&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;mhz&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;open&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;opengl&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;out&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;pci&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;power&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;vpu&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;white&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
              &lt;lst&gt;
                &lt;str name="field"&gt;features&lt;/str&gt;
                &lt;str name="value"&gt;x&lt;/str&gt;
                &lt;int name="count"&gt;2&lt;/int&gt;
              &lt;/lst&gt;
            &lt;/arr&gt;
          &lt;/lst&gt;
        &lt;/arr&gt;
      &lt;/lst&gt;
    &lt;/arr&gt;
  &lt;/lst&gt;
&lt;/lst&gt;
&lt;/response&gt;</pre>
<p>As shown in the example, also in this case Solr had no problems with the correct calculation of the hierarchy. The  above example is almost the same, in the context of data available, as  the previous example, it only contains one more level of depth.</p>
<h3>A few words at the end</h3>
<p>In my opinion this is one of the more useful features for &#8220;<em>ordinary</em>&#8221; user. Unfortunately, so far only available in development version of Solr. I  have not found any information about whether it is planned to transfer  this functionality to version 1.5 of Solr, which is named <em>branch_3x</em> branch in SVN. However, it is important that this functionality was  commited, and sooner or later Solr users will be able to use it.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2010/10/25/hierarchical-faceting-pivot-facets-in-trunk/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>The scope of Solr faceting</title>
		<link>https://solr.pl/en/2010/08/23/the-scope-of-solr-faceting/</link>
					<comments>https://solr.pl/en/2010/08/23/the-scope-of-solr-faceting/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 23 Aug 2010 12:07:58 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[date faceting]]></category>
		<category><![CDATA[facet]]></category>
		<category><![CDATA[facet method]]></category>
		<category><![CDATA[facet parameter]]></category>
		<category><![CDATA[facet query]]></category>
		<category><![CDATA[faceting]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[local params]]></category>
		<category><![CDATA[params]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[range faceting]]></category>
		<category><![CDATA[solr]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=69</guid>

					<description><![CDATA[Faceting is one of the ways to categorize the content found in the process of information retrieval. In case of Solr this is the division of set of documents on the basis of certain criteria: content of individual fields, queries]]></description>
										<content:encoded><![CDATA[<p>Faceting is one of the ways to categorize the content found in the  process of information retrieval. In case of Solr this is the division  of set of documents on the basis of certain criteria: content of  individual fields, queries or on the basis of compartments or dates. In  today&#8217;s entry I will try to some scope on the possibility of using the  faceting mechanism, both currently available in Solr 1.4.1, as well as  what will be available in the future.</p>
<p><span id="more-69"></span></p>
<p>One of the few sources of information about faceting is Solr wiki &#8211;  to be more specific &#8211; the page at:  <a href="http://wiki.apache.org/solr/SimpleFacetParameters" target="_blank" rel="noopener noreferrer">http://wiki.apache.org/solr/SimpleFacetParameters</a>. The following article  is an extension to the information available on the wiki website.</p>
<p>Solr faceting mechanism can be divided into four basic types:</p>
<ul>
<li>field faceting,</li>
<li>query faceting,</li>
<li>date faceting,</li>
<li>range facteing.</li>
</ul>
<p>To turn Solr faceting mechanism on, one need to pass <em>facet</em> parameter with the value <em>true</em>.</p>
<h3>Field faceting</h3>
<p>First type of faceting. This type of faceting categorize documents  found due to specified field. With this type of faceting we are able to  get a number of documents found for example in each category or  geographical location. Faceting by field is characterized by a large  number of options which configure its behavior. This are the parameters  available for use:</p>
<ul>
<li><em>facet.field</em> &#8211; parameter specifying which field will be  used to perform faceting. This parameter can be specified multiple  times. Remember that adding multiple <em>facet.field</em> parameters to the query can affect performance.</li>
<li><em>facet.prefix</em> &#8211; restricts faceting results to those that begin with the specified  prefix. The parameter can be defined for each field specified by the <em>facet.field</em> parameter &#8211; you can do it, by adding a parameter like this: <em>facet.field_name.prefix</em>. This parameter is a relatively simple way to implement autocomplete mechanism.</li>
<li><em>facet.sort</em> &#8211; specifies how to sort faceting results. If You use Solr version lower than 1.4, this parameter takes values of <em>true </em>or <em>false</em> indicating successively &#8211; sort by the number of results and sort by  index order (in the case of ASCII this means alphabetical sorting). If  however You are using Solr version 1.4 or higher You should use <em>count</em> value (meaning the same as <em>true</em>), or <em>index</em> value (meaning the same as <em>false</em>). The default value for this parameter is <em>true/count</em> when <em>facet.limit</em> set to 0 or <em>false/index</em> for other values of <em>facet.limit</em> parameter. The parameter can be defined for each field specified by the <em>facet.field</em> parameter.</li>
<li><em>facet.limit</em> &#8211; parameter specifying how many unique values of faceting results to  display. A negative value for this parameter mean no limit. Please note  that the larger the limit, the more memory you need and the longer query  execution. Default parameter value is 100. The parameter can be defined  for each field specified by the <em>facet.field</em> parameter.</li>
<li><em>facet.offset</em> &#8211; parameter defining from offset (from the first faceting result) of  presented faceting results. Default parameter value is 0. This parameter  is designed to help implementing faceting result paging. The parameter  can be defined for each field specified by the <em>facet.field</em> parameter.</li>
<li><em>facet.mincount</em> &#8211; parameter specifying the minimum size of result to be included in  faceting results. The default value is 0. The parameter can be defined  for each field specified by the <em>facet.field</em> parameter.</li>
<li><em>facet.missing</em> &#8211; parameter specifying whether, in addition to standard faceting  results, number of documents without a value in the specified field  should be included. This parameter can take values of <em>true</em> or <em>false</em>. The default parameter value is <em>false</em>. The parameter can be defined for each field specified by the <em>facet.field</em> parameter.</li>
<li><em>facet.method &#8211; </em>parameter introduced in Solr 1.4. It takes the value of <em>enum</em> or <em>fc</em>. Specifies a method for faceting calculation. Setting this parameter to <em>enum</em> effects in using term enumeration to calculate faceting results. This  method is proven to be most efficient when dealing with fields with  small number of unique terms. The second method, labeled <em>fc</em>, is  the standard method for faceting calculation. It takes all the results  and iterate over all documents in the result set. The parameter can be  defined for each field specified by the <em>facet.field</em> parameter. The default value is <em>fc</em> for all the fields not based on <em>Boolean</em> type.</li>
<li><em>facet.enum.cache.minDf</em> &#8211; parameter with strange sounding name specifying the minimum number of matching documents to a single term to the <em>fc </em>method to be used for faceting result calculation. I know it sounds strange but i do not know how to explain it easier <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></li>
</ul>
<p>These are the parameters of field faceting. In case of most  parameters I have written that there is a possibility to define their  values for each field specified by <em>facet.field</em> parameter. How does it look like ? Suppose we have a query like this:
</p>
<pre class="brush:xml">q=solr&amp;facet=true&amp;facet.field=category&amp;facet.field=location</pre>
<p>It is a simple query for &#8216;solr&#8217; term with faceting mechanism turned on. There are two facet fields defined &#8211; <em>category</em> and <em>location</em>. Lets say, that we would like to have 200 facet results for <em>category </em>field sorted by count and 50 facet results for <em>location</em> field sorted alphabetically. To do that we add the following fragment to the query shown above:
</p>
<pre class="brush:xml">facet.category.limit=200&amp;facet.category.sort=count&amp;facet.location.limit=50&amp;facet.location.sort=index</pre>
<p>As shown we can easily modify facet mechanism behavior for individual facet fields.</p>
<h3>Query faceting</h3>
<p>Facet mechanism based on a single parameter &#8211; <em>facet.query</em> to  which we give a query. The query passed to the parameter must be  constructed so that standard Lucene query parser can understand it. An example use of this parameter is, for example query a group of pricing, which could look like:
</p>
<pre class="brush:xml">facet.query=price: [0+TO+100]</pre>
<p>Note,  however, that each added <em>facet.query</em> parameter is another  query to Lucene, which means performance loss. Many <em>facet.query</em> parameters in a query can be painful to Solr.</p>
<p>There is one more thing worth mentioning when  talking about query faceting &#8211; there is a possibility to define your own  parser to parse <em>facet.query</em> parameter value. To use your own parser, for example, called <em>myParser</em> parameter passed to Solr should look like this:
</p>
<pre class="brush:xml">facet.query={!myParser}aaa</pre>
<h3>Date faceting</h3>
<p>New faceting functionality introduced in Solr 1.3. Date faceting allows you to calculate faceting results including all the intricacies of processing dates. Please note that date faceting can only be used with fields based on the type <em>solr.</em><em>DateField</em>. Now let&#8217;s get on with the parameters associated with date faceting:</p>
<ul>
<li><em> facet.date</em> &#8211; like <em>facet.field</em> parameter, this parameter is used to identify fields where dates faceting should be used. As  in the case of <em>facet.field</em> parameter you can specify this parameter  several times to allow date faceting on many fields in one  query.</li>
<li><em>facet.date.start &#8211; </em>parameter  specifying the lower limit of date on which the faceting calculation  should be started. This parameter can be defined for each field  specified by the <em>facet.date </em>parameter. This parameter is mandatory when using <em>facet.date</em> and should be defined for each <em>facet.date</em> parameter.</li>
<li><em>facet.date.end</em> &#8211; parameter defining the upper limit of the date, on which the faceting  calculation should be ended. This parameter can be defined for each  field specified by the <em>facet.date </em>parameter. This parameter is mandatory when using <em>facet.date </em>and should be defined for each <em>facet.date</em> parameter.</li>
<li><em>facet.date.gap</em> &#8211; parameter specifying date compartments to be generated for the defined boundaries. This parameter is mandatory when using <em>facet.date</em> and should be defined for each <em>facet.date</em> parameter. The parameter can be defined for each field specified by the <em>facet.date </em>parameter.</li>
<li><em>facet.date.hardend</em> &#8211; parameter taking values <em> true </em>and <em>false</em>, telling Solr what to do in the case when the parameter <em>facet.date.gap</em> is not evenly splitting the compartments. If we set this parameter to <em>true</em> the last compartment generated by <em>facet.date.gap</em> parameter can be wider than the boundary defined by <em>facet.date.end</em> parameter. If we set this parameter to <em>false</em> (default value) the last compartment generated by <em>facet.date.gap</em> parameter can be smaller then the rest of the ranges. The parameter can be defined for each field specified by the <em>facet.date </em>parameter.</li>
<li><em>facet.date.other</em> &#8211; parameter specifying what values besides the standard ones (ranges)  should be added to results of date faceting. The parameter can be  defined for each field specified by the <em>facet.date </em>parameter. The parameter can take following values:
<ul>
<li><em>before </em>&#8211; in addition to the standard date faceting  results, there will be one more &#8211; number of documents with a date before  the one defined in the <em>facet.date.start</em> parameter,</li>
<li><em>after</em> &#8211; in addition to the standard date faceting results, there will be one  more &#8211; number of documents with the date after the one defined in the <em>facet.date.end</em> parameter,</li>
<li><em>between </em>&#8211; in addition to the standard date faceting results, there will be one more &#8211; number of documents with the date between <em>facet.date.start</em> and <em>facet.date.end</em> parameters,</li>
<li><em>all</em> &#8211; a shortcut to define all the above,</li>
<li><em>none </em>&#8211; none of the additional results will be added to date faceting results.</li>
</ul>
</li>
<li><em>facet.date.include</em> &#8211; parameter that will be introduced  in Solr 4.0. It allows of closing or opening of the compartments  defined by the boundaries and the gap. The parameter will accept the  following values:
<ul>
<li><em>lower</em> &#8211; each of the resulting compartment will contain its lower limit,</li>
<li><em>upper</em> &#8211; each of the resulting compartment will contain its upper limit,</li>
<li><em>egde</em> &#8211; the first and last interval will include its external borders &#8211; that  is, for the first lower and upper range for the last interval,</li>
<li><em>outer</em> &#8211; a parameter specifying that the compartments defined by the values <em>before</em> and <em>after</em> of the <em>facet.date.other</em> parameter will contain its borders, even if other compartments already contain these borders,</li>
<li><em>all</em> &#8211; a parameter that causes the inclusion of all of the above options.</li>
</ul>
</li>
</ul>
<p>That is how we can modify the behavior of the date faceting. Now, some example of using this kind of faceting:
</p>
<pre class="brush:xml">q=solr&amp;facet=true&amp;facet.date=addDate&amp;facet.date.start=NOW/DAY-30DAYS&amp;facet.date.end=NOW/DAY%2B30DAYS&amp;facet.date.gap=%2B1DAY</pre>
<p>What does the above query do ? We turn the faceting mechanism on, we define date faceting for <em>addDate</em> field. What we want to get is the compartments between 30 days before today (<em>NOW/DAY-30DAYS</em>) and 30 days after today (<em>NOW/DAY+30DAYS)</em>. The compartments will be of the size of a single day.</p>
<h3>Range faceting</h3>
<p>Functionality which will be available in Solr 3.1. If someone want to test it right now, both the trunk and branch 3.x have this  functionality implemented. This method of faceting is the extension of  date faceting. This functionality works similar to date faceting &#8211; as a  result we get a list of compartments constructed automatically based on  parameters. Here are the list of parameters that can be used to define  range faceting behavior:</p>
<ul>
<li><em> facet.range </em>&#8211; like <em>facet.field</em> parameter, this parameter is used to identify fields where range faceting should be used. As  in the case of <em>facet.field</em> parameter you can specify this parameter  several times to allow range faceting on many fields in one  query.</li>
<li><em>facet.range.start &#8211; </em>parameter   specifying the lower limit of range on which the faceting calculation   should be started. This parameter can be defined for each field  specified  by the <em>facet.range </em>parameter. This parameter is mandatory when using <em>facet.range </em>and should be defined<em> </em>for each <em>facet.range</em> parameter.</li>
<li><em>facet.range.end</em> &#8211; parameter defining the upper limit of the range, on which the  faceting  calculation should be ended. This parameter can be defined for  each field specified  by the <em>facet.range </em>parameter. This parameter is mandatory when using <em>facet.range </em>and should be defined<em> </em>for each <em>facet.range</em> parameter.</li>
<li><em>facet.range.gap</em> &#8211; parameter specifying range compartments to be generated for the defined boundaries. This parameter is mandatory when using <em>facet.range</em> and should be defined for each <em>facet.date</em> parameter. The parameter can be defined for each field specified by the <em>facet.date </em>parameter.</li>
<li><em>facet.range.hardend</em> &#8211; parameter taking values <em> true </em>and <em>false</em>, telling Solr what to do in the case when the parameter <em>facet.range.gap</em> is not evenly splitting the compartments. If we set this parameter to <em>true</em> the last compartment generated by <em>facet.range.gap</em> parameter can be wider than the boundary defined by <em>facet.range.end</em> parameter. If we set this parameter to <em>false</em> (default value) the last compartment generated by <em>facet.range.gap</em> parameter can be smaller then the rest of the ranges. The parameter can be defined for each field specified by the <em>facet.range</em>parameter.</li>
<li><em>facet.range.other</em> &#8211; parameter specifying what values besides the standard ones (ranges)   should be added to results of range faceting. The parameter can be   defined for each field specified by the <em>facet.range </em>parameter. The parameter can take following values:
<ul>
<li><em>before </em>&#8211;  in addition to the standard range faceting  results, there will be one  more &#8211; number of documents with a values  lower than the one defined in the <em>facet.range.start</em> parameter,</li>
<li><em>after</em> &#8211; in addition to the standard range faceting results, there will be one   more &#8211; number of documents with the values higher than the one defined  in the <em>facet.range.end</em> parameter,</li>
<li><em>between </em>&#8211; in addition to the standard range faceting results, there will be one more &#8211; number of documents with the values between <em>facet.range.start</em> and <em>facet.range.end</em> parameters,</li>
<li><em>all</em> &#8211; a shortcut to define all the above,</li>
<li><em>none </em>&#8211; none of the additional results will be added to range faceting results.</li>
</ul>
</li>
<li><em>facet.range.include</em> &#8211; parameter allowing closing  or  opening of the compartments defined by the boundaries and the gap.  The  parameter will accept the following values:
<ul>
<li><em>lower</em> &#8211; each of the resulting compartment will contain its lower limit,</li>
<li><em>upper</em> &#8211; each of the resulting compartment will contain its upper limit,</li>
<li><em>egde</em> &#8211; the first and last interval will include its external borders &#8211; that   is, for the first lower and upper range for the last interval,</li>
<li><em>outer</em> &#8211; a parameter specifying that the compartments defined by the values <em>before</em> and <em>after</em> of the <em>facet.range.other</em> parameter will contain its borders, even if other compartments already contain these borders,</li>
<li><em>all</em> &#8211; a parameter that causes the inclusion of all of the above options.</li>
</ul>
</li>
</ul>
<p>As you can see the range faceting parameters are almost identical to  those in date faceting. The behavior is also almost identical. An  example query using ranges faceting may be the following query:
</p>
<pre class="brush:xml">q=solr&amp;facet=true&amp;facet.range=price&amp;facet.range.start=0&amp;facet.range.end=1000&amp;facet.range.gap=100</pre>
<p>So, we went through all of the types of faceting. But thats not all.  Users of Solr version 1.4 and higher have the opportunity to use the  so-called LocalParams.</p>
<h3>LocalParams and faceting</h3>
<p>Suppose we have a requirement.﻿ We  have a query that returns search results for the term &#8216;solr&#8217; and in  which we have defined two filters, one for category and one for the  country of origin of the document. In addition to the search results we  want to enable navigation through the regions and categories, but we  would like them not to be dependend on each other. That is, we want to  give the opportunity to navigate through the regions for the term &#8216;solr&#8217;  but we dont want it to be limited to the selected category, and vice  versa. To do it in Solr version 1.3 or earlier, we would write the  following query:
</p>
<pre class="brush:xml">q=solr&amp;fq=category:search&amp;fq=region:poland
q=solr&amp;facet=true&amp;facet.field=category&amp;facet.field=region</pre>
<p>Two  queries, because first we have to get narrowed search results, on the  other hand we need the faceting result not to be narrowed by filters.  For Solr version 1.4 or higher, we can shorten this to one query. For  this purpose, we use the possibility of tagging and exclusion of tagged  parameters. First we change the query as follows:
</p>
<pre class="brush:xml">q=solr&amp;fq={!tag=categoryFQ}fq=category:search&amp;fq={!tag=regionFQ}region:poland</pre>
<p>For  now, the search results will not change. We added tags to the filters  in the above query so we can later exclude them in faceting. Then we  modify the second query as follows:
</p>
<pre class="brush:xml">q=solr&amp;facet=true&amp;facet.field={!ex=categoryFQ,regionFQ}category&amp;facet.field={!ex=categoryFQ,regionFQ}region</pre>
<p>So far the faceting results will not change. We added exclusions to the <em>facet.field</em> parameters, so filters named <em>categoryFQ</em> and <em>regionFQ</em> will not be taken into consideration when calculating faceting results.</p>
<p>Then we combine the modified query, so it should look as follows:
</p>
<pre class="brush:xml">q=solr&amp;fq={!tag=categoryFQ}fq=category:search&amp;fq={!tag=regionFQ}region:poland&amp;facet=true&amp;facet.field={!ex=categoryFQ,regionFQ}category&amp;facet.field={!ex=categoryFQ,regionFQ}region</pre>
<p>I`ll write more about LocalParams in a future entries.</p>
<h3>A few words at the end</h3>
<p>I  hope that this article approached the possibility of using Solr  faceting, both in earlier versions of Solr, in the present, as well as  those that arise in the nearest future.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2010/08/23/the-scope-of-solr-faceting/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>6 deadly sins in the context of query</title>
		<link>https://solr.pl/en/2010/08/11/6-deadly-sins-in-the-context-of-query/</link>
					<comments>https://solr.pl/en/2010/08/11/6-deadly-sins-in-the-context-of-query/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Wed, 11 Aug 2010 12:04:37 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[facet]]></category>
		<category><![CDATA[facet.limit]]></category>
		<category><![CDATA[facet.offset]]></category>
		<category><![CDATA[faceting]]></category>
		<category><![CDATA[how to query]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[solr query]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=62</guid>

					<description><![CDATA[In my work related to Lucene and Solr I have seen various queries. While in the case of Lucene, developer usually knows what he/she wants to achieve and use more or less optimal solution, but when it comes to Solr]]></description>
										<content:encoded><![CDATA[<p>In my work related to Lucene and Solr I have seen various queries. While in the case of Lucene, developer usually knows what he/she wants to achieve and use more or less optimal solution, but when it comes to Solr it is not always like this. Solr is a product which could theoretically be used by everyone, both the person who knows Java, one that does not have a broad and specialized technical knowledge, as well as programmer. Precisely because of that Solr is a product which is easy to run and use it, at least when it comes to simple functionalities. I suppose, that is why not many people are worried about reading Solr wiki or at least review the mailing list. As a result, sooner or later people tend to make mistakes. Those errors arise from various shortcomings &#8211; lack of knowledge about Solr, lack of skills, lack of experience or simply a lack of time and tight deadlines. Today I would like to show some major mistakes when submitting queries to Solr and how to avoid those mistakes.</p>
<p><span id="more-62"></span></p>
<h3>1. Lack of filters</h3>
<p>One of the fundamental errors that I encounter from time to time is the lack of filters, which in context of query means no fq parameter. Let us remember that filters are out friends <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Remember that because of filters Solr cache is used more optimally. Filter do not affect relevance of the document in the context of query and search results (score factor), and thus, we can perform filtering without fear of the change in the score value of individual documents (useful for example in e-commerce for product groups narrowing).</p>
<h3>2. Logical conditions and q parameter</h3>
<p>Another of the &#8220;sins&#8221; that I come across quite often is a one with close relationship with the previous point. It&#8217;s not a bug in the literal sense, but it is an area where a simple change will have a significant influence on performance. Assuming that the default logical operator is <em>OR</em>, imagine your query in the form of: <code>q=(java+design+patterns)+AND+category:books+AND+promotion:true+AND+publisher:ABC</code>. This query is correct from the perspective of the application logic, where we get the appropriate group search results. But what if we also want to optimally use Solr cache and thus boost performance. The anserw is quite simple &#8211; move some of the terms to filters. By changing out a query to <code>q=java+design+patterns&amp;fq=category:books&amp;fq=promotion:true&amp;fq=publisher:ABC</code> Solr benefit from two types of cache &#8211; queryDocumentCache to retrieve documents for a query with parameter q and the filterCache for each of the filters. With the change of the query we were able to optimize the query to use two types of cache and in addition to optimize the entries of queryDocumentsCache (due to the shortening of the query parameter <em>q</em>).</p>
<h3>3. Hugh numbers of facet queries</h3>
<p>Another &#8220;sin&#8221; associated with handling groups of documents. Quite often, especially, in applications that can categorize products in many ways, I have met queries with a lot of facet.query parameters that correspond to the grouping of documents. Grouping by price, location, product groups, and so on. A good example is grouping by price where the business customer can set the price ranges for each category and then application must group products by those ranges. This leads to queries that have 100, 200 or more<em> facet.query</em> parameters added. Please remember that each <em>facet.query</em> has an impact on efficiency, not to mention 100 or 200 of them. If we are interested in a quick response from Solr we can not make such a queries. In such cases, I always propose modifying the index structure if needed, and they are needed in most cases. Some modifications (like defining ranges at index time) allows to eliminate tens or hundreds of <em>facet.query</em> for one <em>facet.field</em> parameter. But this method is associated to another problem &#8211; explanation for the customer, why &#8220;re-index button&#8221; must be pressed after range changes. As a rule, however, performance testing at high loads and large variety of queries speak for themselves.</p>
<h3>4. Facet limits</h3>
<p>The problem appears in the line where Solr meets business logic. An example of this &#8220;sin&#8221; is a simple list of categories that a customer wants to have displayed depending on user location on the website. When we have a small numbers of categories we do not have a problem, but what about thousands of categories. Very often, I met with the approach taken by the developers to retrieve all categories of Solr (with increased <em>facet.limit</em> parameter compared to the default value) and choose the right categories in the application that is using Solr. I think this approach can generate problems &#8211; first of all faceting requires memory, second aggregating of facet elements need time, and of course getting all of the 50.000 categories with it&#8217;s counts can be painful to Solr. If we want a fast queries, try to use the parameter facet.limit reasonable. If You need many facet results try to build your application so it can use <em>facet.offset</em> parameter and therfore use paging. If this is not possible, at least configure Your container to have enough memory to handle parallel queries and get ready to have queries that can perform longer when having high facet.limit value.</p>
<h3>5. Downloading of unnecessary data</h3>
<p>Very common problem is the retrieval of all information, not just those that we need. Of course, the problem does not apply to deployments where Sole offers information such as, for example, only the product ID. However, a large number of deployments that I&#8217;ve deal with was based almost entirely on Solr, and hence Solr index was made up of multiple stored fields. Developers using Solr very rarely used the parameter<em> fl</em> and the possibility of limiting the fields that are returned. In extreme cases, this led to problems with the amount of data that had to be sent over the network.</p>
<h3>6. Many requests to obtain count of groups of documents</h3>
<p>In some applications more important than the actual search capabilities were the navigation, where users can browse document repository by it&#8217;s feature, like department, category, subcategory, and so on. Very often, in addition to names there are also numbers displayed &#8211; the numbers of documents with this feature. I met cases were the number of documents were obtained using a separate query. Effect &#8211; 100 categories displayed on a web page led to 100 separate queries to Solr. Do not go this way, if You have to modify the Solr index to use the facet mechanism. Maybe at that time it will be more work, but certainly in the long run this is worth it.</p>
<h3>A few words at the end</h3>
<p>Please note that these are just examples that I think are fairly universal, at least, which I quite often encountered during my work. They are not all the errors that happen when using the Solr, but I hope to highlight some of the mistakes people tend to make and how to go around them.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2010/08/11/6-deadly-sins-in-the-context-of-query/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
