<?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>faceting &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/faceting-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>Sat, 14 Nov 2020 13:52:40 +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>Solr 5.1: New faceting API (quick look)</title>
		<link>https://solr.pl/en/2015/05/30/solr-5-1-new-faceting-api-quick-look/</link>
					<comments>https://solr.pl/en/2015/05/30/solr-5-1-new-faceting-api-quick-look/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Sat, 30 May 2015 12:52:11 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[5.1]]></category>
		<category><![CDATA[faceting]]></category>
		<category><![CDATA[solr]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=861</guid>

					<description><![CDATA[With the recent release of Solr 5.1 we&#8217;ve got a nice, new functionalities in Solr. One of those new features is the new faceting module that allows to send reuquests in JSON format in the request body. In this blog]]></description>
										<content:encoded><![CDATA[<p>With the recent <a title="Lucene &amp; Solr 5.1" href="http://solr.pl/en/2015/04/14/lucene-solr-5-1/">release of Solr 5.1</a> we&#8217;ve got a nice, new functionalities in Solr. One of those new features is the new faceting module that allows to send reuquests in JSON format in the request body. In this blog entry we will try to quickly look at the functionality and see how Sorl changes when it comes to real time data analysis.</p>
<p><span id="more-861"></span></p>
<h3>Test data</h3>
<p>For the purpose of our tests I&#8217;ll use the data provided with the default Solr distribution. To run Solr and index the data I use the following command:
</p>
<pre class="brush:xml">bin/solr start -e techproducts
</pre>
<p>Starting Solr using this command will result in both starting Solr and indexing the data to a new collection called <em>techproducts</em>.</p>
<h3>The first example</h3>
<p>Let&#8217;s start with a very simple example of using the new faceting module &#8211; let&#8217;s try running a query that will result in Solr returning a list of categories and manufactures of our products with counts. The query we are used to would look as follows:
</p>
<pre class="brush:xml">curl 'localhost:8983/solr/techproducts/select?q=*:*&amp;rows=0&amp;indent=true&amp;facet=true&amp;facet.field=manu_id_s&amp;facet.field=cat'
</pre>
<p>The query that will use the new faceting API looks as follows:
</p>
<pre class="brush:xml">curl http://localhost:8983/solr/techproducts/query -d 'q=*:*&amp;rows=0&amp;
 json.facet={
  categories : {
   terms : {
    field: cat
   }
  },
  producers : {
   terms : {
    field: manu_id_s
   }
  }
 }'
</pre>
<p>The result returned by Solr is as follows:
</p>
<pre class="brush:xml">{
  "responseHeader":{
    "status":0,
    "QTime":2,
    "params":{
      "q":"*:*",
      "json.facet":"{\n  categories : {\n   terms : {\n    field: cat\n   } \n  },\n  manu : {\n   terms : {\n    field: manu_id_s\n   }\n  }\n}",
      "rows":"0"}},
  "response":{"numFound":32,"start":0,"docs":[]
  },
  "facets":{
    "count":32,
    "categories":{
      "buckets":[{
          "val":"electronics",
          "count":12},
        {
          "val":"currency",
          "count":4},
        {
          "val":"memory",
          "count":3},
        {
          "val":"connector",
          "count":2},
        {
          "val":"graphics card",
          "count":2},
        {
          "val":"hard drive",
          "count":2},
        {
          "val":"search",
          "count":2},
        {
          "val":"software",
          "count":2},
        {
          "val":"camera",
          "count":1},
        {
          "val":"copier",
          "count":1}]},
    "manu":{
      "buckets":[{
          "val":"corsair",
          "count":3},
        {
          "val":"belkin",
          "count":2},
        {
          "val":"canon",
          "count":2},
        {
          "val":"apple",
          "count":1},
        {
          "val":"asus",
          "count":1},
        {
          "val":"ati",
          "count":1},
        {
          "val":"boa",
          "count":1},
        {
          "val":"dell",
          "count":1},
        {
          "val":"eu",
          "count":1},
        {
          "val":"maxtor",
          "count":1}]}}}
</pre>
<p>As we can see &#8211; both the query and the results is not somthing we are used to, let&#8217;s discuss both briefly.</p>
<h4>Zapytanie</h4>
<p>The second query has been sent do the <em>query</em> handler, but that is not that important. What we are interested in is the query itself. All the parameters of the query were not send as the HTTP request parameters, but instead we&#8217;ve included them in the request body, although still in a form that we are used to. In addition to that, we&#8217;ve included a new thing <em>&#8211; </em>the <em>facet.json</em> parameter, which will holds our faceting definition.</p>
<p>In Solr 5.1, each faceting definition we want to use should be defined as follows:
</p>
<pre class="brush:xml">NAME: {
 TYPE: {
  PARAMETER: PARAMETER_VALUE
  ...
  PARAMETER: PARAMETER_VALUE
 }
}
</pre>
<p>In Solr 5.2 this format will be slightly changed, but we will get back to it once Solr 5.2 will be released. In our example we&#8217;ve used the <em>terms</em> faceting type, which works similar to the <em>facet.field</em> we are used to. The other possible types are for example <em>query</em> or <em>range</em>. Each of those type have a certain properties that can be used with them &#8211; we advise to visit offical Solr documentation to get information on what the parameters are.</p>
<h4>The results</h4>
<p>If we would look at the results returned by Solr we will see something called <em>buckets</em>. Those are <em>key &#8211; value</em> pairs that describe the returned faceting results. Something new, but we&#8217;ve already seen that with the standard faceting, just named differently. However, when using the new faceting API we can expect two types of responses &#8211; one is the <em>buckets</em> and the other is a single value. We will get back to it and describe why it is important when Solr 5.2 will be released.</p>
<h3>Faceting and functions</h3>
<p>Let&#8217;s try one more example &#8211; finding the average price for our products and the 99 percentile. With the new faceting API it is quick and easy &#8211; we can use functions in faceting. For example, the query that will fullfil our requirement looks as follows:
</p>
<pre class="brush:xml">curl http://localhost:8983/solr/techproducts/query -d 'q=*:*&amp;rows=0&amp;
 json.facet={
  average:"avg(price)",
  percentile:"percentile(price,99)"
 }'
</pre>
<p>The response generated by Solr looks as follows:
</p>
<pre class="brush:xml">{
  "responseHeader":{
    "status":0,
    "QTime":2,
    "params":{
      "q":"*:*",
      "json.facet":"{\n  average:\"avg(price)\",\n  percentile:\"percentile(price,99)\"\n }",
      "rows":"0"}},
  "response":{"numFound":32,"start":0,"docs":[]
  },
  "facets":{
    "count":32,
    "average":164.10218846797943,
    "percentile":1966.6484985351556}}
</pre>
<p>Solr returned the results we wanted in the form of single value for each faceting.</p>
<h3>What&#8217;s next?</h3>
<p>Of course the features we&#8217;ve looked at today is not all that Solr offers and will offer in the near future. First of all the number of functions that we can use in faceting will be extended &#8211; for example we will be able to calculate unique values. In addition to that, in Solr 5.2, we will get the ability to nest facets inside other facets and do calculations like &#8211; getting minimum price for each of the categories that we calculated using <em>terms</em> faceting.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2015/05/30/solr-5-1-new-faceting-api-quick-look/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Autocomplete on multivalued fields using faceting</title>
		<link>https://solr.pl/en/2013/03/25/autocomplete-on-multivalued-fields-using-faceting/</link>
					<comments>https://solr.pl/en/2013/03/25/autocomplete-on-multivalued-fields-using-faceting/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 25 Mar 2013 12:54:50 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[faceting]]></category>
		<category><![CDATA[multivalued]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=544</guid>

					<description><![CDATA[In the previous blog post about auto complete on multi-valued field we discussed how highlighting can help us get the information we are interested in. We also promised that we will get back to the topic and we will show]]></description>
										<content:encoded><![CDATA[<p>In the <a href="http://solr.pl/en/2013/02/25/autocomplete-on-multivalued-fields-using-highlighting/">previous</a> blog post about auto complete on multi-valued field we discussed how highlighting can help us get the information we are interested in. We also promised that we will get back to the topic and we will show how to achieve a similar functionality with the use of Solr faceting capabilities. So, let&#8217;s do it.</p>
<p><span id="more-544"></span></p>
<h2>Before we start</h2>
<p>Because this post is more or less a continuation of what we&#8217;ve wrote earlier about autocomplete on multi-valued fields we recommend to read the &#8220;<a href="http://solr.pl/en/2013/02/25/autocomplete-on-multivalued-fields-using-highlighting/"><em>Autocomplete on multivalued field using highlighting</em></a>&#8221; before reading the rest of this entry. We would also like to note, that the method shown in this entry is very similar to the one shown in the &#8220;<a href="http://solr.pl/en/2010/10/18/solr-and-autocomplete-part-1/">Solr and autocomplete (part 1)</a>&#8221; post, but we wanted to refresh that topic and show the example using multi-valued fields.</p>
<h2>Configuration</h2>
<p>Similar to the previous post we will start with Solr configuration.</p>
<h3>Index structure</h3>
<p>The structure of our index is exactly the same as the one previously shown, but let&#8217;s recall it. One thing &#8211; please remember that we want to have auto complete working on multi-valued field. This field is called <em>features</em> and the whole index fields configuration looks like this:
</p>
<pre class="brush:xml">&lt;fields&gt;
 &lt;field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /&gt;
 &lt;field name="features" type="string" indexed="true" stored="true" multiValued="true"/&gt;
 &lt;field name="features_autocomplete" type="text_autocomplete" indexed="true" stored="true" multiValued="true"/&gt;

 &lt;field name="_version_" type="long" indexed="true" stored="true"/&gt;
&lt;/fields&gt;</pre>
<p>For getting values for auto complete we will use the <em>features_autocomplete</em> field.</p>
<h3>Copy field</h3>
<p>Of course we don&#8217;t want to change our indexer and we want Solr to automatically copy the data from <em>features</em> field to the <em>features_autocomplete</em> one. Because of that we will add the <em>copyField</em> definition to the <em>schema.xml</em> file, so it looks like this:
</p>
<pre class="brush:xml">&lt;copyField source="features" dest="features_autocomplete"/&gt;</pre>
<h3>Our text_autocomplete field type</h3>
<p>And we&#8217;ve come to the first difference &#8211; the <em>text_autocomplete</em> field type. This time it looks like this:
</p>
<pre class="brush:xml">&lt;fieldType name="text_autocomplete" class="solr.TextField" positionIncrementGap="100"&gt;
 &lt;analyzer&gt;
  &lt;tokenizer class="solr.KeywordTokenizerFactory"/&gt;
  &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
 &lt;/analyzer&gt;
&lt;/fieldType&gt;</pre>
<p>Because of the fact that we will use faceting we use the <em>solr.KeywordTokenizerFactory</em> with the <em>solr.LowerCaseFilterFactory</em> to have the data in our field as a single, lowercased token.</p>
<h3>Example data</h3>
<p>Our example data is identical to what we had before, but even though let&#8217;s recall them for things to be clear:
</p>
<pre class="brush:xml">&lt;add&gt;
 &lt;doc&gt;
  &lt;field name="id"&gt;1&lt;/field&gt;
  &lt;field name="features"&gt;Multiple windows&lt;/field&gt;
  &lt;field name="features"&gt;Single door&lt;/field&gt;
 &lt;/doc&gt;
 &lt;doc&gt;
  &lt;field name="id"&gt;2&lt;/field&gt;
  &lt;field name="features"&gt;Single window&lt;/field&gt;
  &lt;field name="features"&gt;Single door&lt;/field&gt;
 &lt;/doc&gt;
 &lt;doc&gt;
  &lt;field name="id"&gt;3&lt;/field&gt;
  &lt;field name="features"&gt;Multiple windows&lt;/field&gt;
  &lt;field name="features"&gt;Multiple doors&lt;/field&gt;
 &lt;/doc&gt;
&lt;/add&gt;</pre>
<h2>Query with faceting</h2>
<p>Let&#8217;s look how our query will look like when we will use faceting instead of highlighting.</p>
<h3>Full query</h3>
<p>When using faceting our query should look more or less like the following one:
</p>
<pre class="brush:xml">q=*:*&amp;rows=0&amp;facet=true&amp;facet.field=features_autocomplete&amp;facet.prefix=sing</pre>
<p>A few words about the parameters:</p>
<ul>
<li><em>rows=0</em> &#8211; we tell Solr that we don&#8217;t want the documents that matched the query in the results,</li>
<li><em>facet=true</em> &#8211; we inform Solr that we want to use faceting,</li>
<li><em>facet.field=features_autocomplete</em> &#8211; we say which field will be used to calculate faceting,</li>
<li><em>facet.prefix=sing</em> &#8211; with the use of this parameter we provide the value of a query for auto complete.</li>
</ul>
<h3>Query results</h3>
<p>Query results returned by Solr for the above query are as follows:
</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;response&gt;
&lt;lst name="responseHeader"&gt;
  &lt;int name="status"&gt;0&lt;/int&gt;
  &lt;int name="QTime"&gt;0&lt;/int&gt;
  &lt;lst name="params"&gt;
    &lt;str name="facet"&gt;true&lt;/str&gt;
    &lt;str name="q"&gt;*:*&lt;/str&gt;
    &lt;str name="facet.prefix"&gt;sing&lt;/str&gt;
    &lt;str name="facet.field"&gt;features_autocomplete&lt;/str&gt;
    &lt;str name="rows"&gt;0&lt;/str&gt;
  &lt;/lst&gt;
&lt;/lst&gt;
&lt;result name="response" numFound="3" start="0"&gt;
&lt;/result&gt;
&lt;lst name="facet_counts"&gt;
  &lt;lst name="facet_queries"/&gt;
  &lt;lst name="facet_fields"&gt;
    &lt;lst name="features_autocomplete"&gt;
      &lt;int name="single door"&gt;2&lt;/int&gt;
      &lt;int name="single window"&gt;1&lt;/int&gt;
    &lt;/lst&gt;
  &lt;/lst&gt;
  &lt;lst name="facet_dates"/&gt;
  &lt;lst name="facet_ranges"/&gt;
&lt;/lst&gt;
&lt;/response&gt;</pre>
<p>As you can see in the field faceting section we got the phrases we were interested in along with the number of documents they appear in.</p>
<h3>What to remember about</h3>
<p>The crucial thing to remember is that the value provided to the <em>facet.prefix</em> parameter is not analyzed. Because of that if we would provide the <em>Sing</em> value instead of the <em>sing</em>we wouldn&#8217;t get the results. You should remember that.</p>
<h2>A short summary</h2>
<p>The above entry shown the second method used to develop auto complete functionality on multi-valued fields. Of couse we didn&#8217;t say all about the topic and we will get back to it someday, but for now that is all. We hope that someone will find it useful <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2013/03/25/autocomplete-on-multivalued-fields-using-faceting/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Solr 1.4: Local Params</title>
		<link>https://solr.pl/en/2011/03/28/solr-1-4-local-params/</link>
					<comments>https://solr.pl/en/2011/03/28/solr-1-4-local-params/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 28 Mar 2011 07:20:29 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[1.4]]></category>
		<category><![CDATA[faceting]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[local params]]></category>
		<category><![CDATA[params]]></category>
		<category><![CDATA[solr]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=225</guid>

					<description><![CDATA[Several months ago, during one of the projects I have tried to construct a query with optimal faceting. The problem was that we need filters (fq) in the query but in the same time we need a faceting that was]]></description>
										<content:encoded><![CDATA[<p>Several months ago, during one of the projects I have tried to construct a query with optimal faceting.  The problem was that we need filters (<em>fq</em>) in the query but in the same time we need a faceting that was not filtered. To some point it was not possible in Solr &#8211; you had to make two queries.  But now, you can do it with one query. Let&#8217;s meet <em>LocalParams</em>.</p>
<p><span id="more-225"></span></p>
<h3>The begining</h3>
<p><em>LocalParams </em>lets you tag part of the query, for example:
</p>
<pre class="brush:xml">q=*:*&amp;fq={!tag=city}city:warszawa</pre>
<p>After  sending the above query to Solr it will remember (in the context of the  same query) that tag named <em>city </em>covers the filter with a value of <em>city: warszawa</em>. Now  suppose that we want to send a query to get all documents that have the <em>warszawa</em> value in the <em>city</em> field (lets suppose that the <em>city </em>field is  multi valued). In addition, we want to Solr to show us the number of documents in all cities. Nothing could be simpler with the use of <em>LocalParams </em>&#8211; just use the parameter <em>{!ex}</em> in the faceting. This could possibly be done by sending the following query to Solr:
</p>
<pre class="brush:xml">q=*:*&amp;fq={!tag=miasto}city:warszawa&amp;facet=true&amp;facet.field={!ex=miasto}city</pre>
<p>The  above query will return documents that have the <em>warszawa </em>value in the <em> city </em>field and faceting calculated on the <em>city </em>field which is not  narowed by the filter query, because we excluded that filter.</p>
<h3>Query parser type</h3>
<p>Of course, the use of <em>LocalParams </em>is not limited to faceting. One of the interesting examples is a type handler definition. If we use <em>standard</em> query parser, we can change its type for a particular query with this structure:
</p>
<pre class="brush:xml">q={!type=dismax qf=city}warszawa</pre>
<p>The  above query will use the <em>dismax </em>query parser and pass the <em>qf=city</em> parameter to it along with the <em>warszawa</em> value in the <em>q</em> parameter.</p>
<h3>Logical operator</h3>
<p>Changing the default logical operator using <em>LocalParams </em>is also very simple:
</p>
<pre class="brush:xml">q={!q.op=AND}warszawa praga</pre>
<p>The above query uses the AND logical operator for terms contained in the parameter <em>q</em>, which are <em>warszawa</em> and <em>praga</em>.</p>
<h3>Parameter dereferencing</h3>
<p>Additionally, by using <em>LocalParams </em>we can achieve an interesting feature &#8211; the parameters dereferencing. For example, if we want to use your own parameter names in queries, we can do it this way:
</p>
<pre class="brush:xml">q={!type=dismax qf=city v=$pmiasto}&amp;pmiasto=warszawa</pre>
<p>Solr  does not support default parameter named <em>pmiasto</em>, but with the key <em>v</em> (meaning value) and use of the reference operator <em>$</em> it was possible to  transfer the value of such a named parameter to the query.</p>
<p>I recommend that everyone who wants to use this feature in your application to play with <em>LocalParams </em>and find out if they fit your needs.</p>
<h3>More information</h3>
<p>Actual information about <em>LocalParams</em> and Solr can be found at Apache Solr wiki at the following address: <a href="http://wiki.apache.org/solr/LocalParams" target="_blank" rel="noopener noreferrer">http://wiki.apache.org/solr/LocalParams</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2011/03/28/solr-1-4-local-params/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Solr and autocomplete (part 1)</title>
		<link>https://solr.pl/en/2010/10/18/solr-and-autocomplete-part-1/</link>
					<comments>https://solr.pl/en/2010/10/18/solr-and-autocomplete-part-1/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 18 Oct 2010 12:16:39 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[faceting]]></category>
		<category><![CDATA[solr]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=88</guid>

					<description><![CDATA[Almost everyone has seen how the autocomplete feature looks like. No wonder, then, Solr provides mechanisms by which we can build such functionality. In today&#8217;s entry I will show you how you can add autocomplete mechanism using faceting. Indeks Suppose]]></description>
										<content:encoded><![CDATA[<p>Almost everyone has seen how the autocomplete feature looks like. No wonder, then, Solr provides mechanisms by which we can build such functionality. In today&#8217;s entry I will show you how you can add autocomplete mechanism using faceting.</p>
<p><span id="more-88"></span></p>
<h3><img fetchpriority="high" decoding="async" class="size-full wp-image-483" title="Google Autocomplete" src="http://solr.pl/wp-content/uploads/2010/10/google_autocomplete2.png" alt="" width="641" height="159"></h3>
<h3>Indeks</h3>
<p>Suppose you want to show some hints to the user in the on-line store, for example you want to show products name. Suppose that our index is composed of the following fields:
</p>
<pre class="brush:xml">&lt;field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/&gt;
&lt;field name="name" type="text" indexed="true" stored="true" multiValued="false" /&gt;
&lt;field name="description" type="text" indexed="true" stored="true" multiValued="false" /&gt;</pre>
<p>A <em>text </em>type is defined as follows:
</p>
<pre class="brush:xml">&lt;fieldType name="text" class="solr.TextField" positionIncrementGap="100"&gt;
 &lt;analyzer&gt;
  &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
&nbsp; &lt;filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/&gt;
&nbsp; &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
 &lt;/analyzer&gt;
&lt;/fieldType&gt;</pre>
<h3>Configuration</h3>
<p>To start, consider what you want to achieve &#8211; do we want to suggest only individual words that make up a name, or maybe full names that begin with the letters specified by the user. Depending on our choices we have to prepare the appropriate field on which we will build hints.</p>
<h3>Prompting individual words that make up the name</h3>
<p>In the case of single words, we should use a field that is tokenized. In our case, the field named <em>name </em>will be sufficient. However, note that if you want to use for example stemming you should define another type, which do not use stemming because of how this analysis operates on the contents of the field.</p>
<h3>Prompting full name</h3>
<p>For full names of the products suggestions we need a different field configuration &#8211; the best for this will be a untokenized field. But we can not use <em>string </em>based field for that. For this purpose, we define the field as follows:
</p>
<pre class="brush:xml">&lt;field name="name_auto" type="text_auto" indexed="true" stored="true" multiValued="false" /&gt;</pre>
<p>This type is defined as follows:
</p>
<pre class="brush:xml">&lt;fieldType name="text_auto" class="solr.TextField"&gt;
 &lt;analyzer&gt;
&nbsp; &lt;tokenizer class="solr.KeywordTokenizerFactory"/&gt;
&nbsp; &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
 &lt;/analyzer&gt;
&lt;/fieldType&gt;</pre>
<p>To not modify the format of the data we also add the appropriate definition of the copy information:
</p>
<pre class="brush:xml">&lt;copyField source="name" dest="name_auto" /&gt;</pre>
<h3>How do we use it ?</h3>
<p>To use the data we prepared we use a fairly simple query:
</p>
<pre class="brush:bash">q=*:*&amp;facet=true&amp;facet.field=FIELD&amp;facet.mincount=1&amp;facet.prefix=USER_QUERY</pre>
<p>Where:</p>
<ul>
<li><em>FIELD</em> &#8211; field on the basis of which we intend to make suggestions. In our case the field named<em></em> <em>name_auto</em>.</li>
<li><em>USER_QUERY </em>&#8211; letters entered by the user.</li>
</ul>
<p>It is worth noting <em>rows=0</em> parameter is added here to only show the faceting result without the query results. Of course, this is not a necessity.</p>
<p>An example query would look like that:
</p>
<pre class="brush:bash">fl=id,name&amp;rows=0&amp;q=*:*&amp;facet=true&amp;facet.field=name_auto&amp;facet.mincount=1&amp;facet.prefix=har</pre>
<p>The result of this query might look like this::
</p>
<pre class="brush:xml">&lt;response&gt;
 &lt;lst name="responseHeader"&gt;
  &lt;int name="status"&gt;0&lt;/int&gt;
  &lt;int name="QTime"&gt;0&lt;/int&gt;
 &lt;/lst&gt;
 &lt;result name="response" numFound="4" start="0"/&gt;
 &lt;lst name="facet_counts"&gt;
  &lt;lst name="facet_queries"/&gt;
  &lt;lst name="facet_fields"&gt;
   &lt;lst name="name_auto"&gt;
    &lt;int name="hard disk"&gt;1&lt;/int&gt;
    &lt;int name="hard disk samsung"&gt;1&lt;/int&gt;
    &lt;int name="hard disk seagate"&gt;1&lt;/int&gt;
    &lt;int name="hard disk toshiba"&gt;1&lt;/int&gt;
   &lt;/lst&gt;
  &lt;/lst&gt;
  &lt;lst name="facet_dates"/&gt;&lt;/lst&gt;
&lt;/response&gt;</pre>
<h3>Additional features</h3>
<p>It is worth to mention the additional opportunities which are inherent to this method.</p>
<p>The first possibility is to show the user additional information such as number of results that you get when you select an appropriate hint. If you want to show such information it will certainly be an interesting option.</p>
<p>The next thing is sorting with the use of <em>facet.sort</em> parameter. Depending on your needs, we can sort the results by the number of documents (the default behavior, parameter set to <em>true</em>) or alphabetically (value set to <em>false</em>).</p>
<p>We may limit the suggestions to those which have more results than a specified number. To take advantage of this opportunity pass in a parameter <em>facet.mincount</em> with the appropriate number.</p>
<p>And as for me the biggest advantage of this method is the possibility of getting only those suggestions that not only match the letters that the user typed but also some other parameters, like category for example. For example, we want to show hints for the user who is in the household section of our store. We suspect that at this moment the user will not be interested in DVD-type products, and therefore we add a parameter <em>fq=department:homeAppliances</em> (assuming that we have such a department). After such a modified query, you do not get hints generated from the entire index, we only get those narrowed to the selected department.</p>
<h3>A few words at the end</h3>
<p>As other method, this one too, have its advantages and disadvantages. The advantage of this solution is its ease of use, no additional components requirement, and that the result hints can be easily narrowed to be generated only from those documents that match the query entered by the user. As a big plus is that the method includes number of result that will be shown after selecting the hint (of course with the same search parameters). For the downside is definitely need to have additional types and fields, quite limited abilities and the load caused by the use of faceting mechanism.</p>
<p>The next entry about the <em>autocomplete </em>will try to expand on and show a further methods of generating hints using Solr.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2010/10/18/solr-and-autocomplete-part-1/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>
