<?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>autocomplete &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/autocomplete/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 14:11:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Autocomplete With Special Characters</title>
		<link>https://solr.pl/en/2017/01/29/autocomplete-with-special-characters/</link>
					<comments>https://solr.pl/en/2017/01/29/autocomplete-with-special-characters/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Sun, 29 Jan 2017 14:11:18 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[solr]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=915</guid>

					<description><![CDATA[Its been a long time since the last real blog post here on solr.pl, but better later than ever, right? So, today we will get back to the topic of autocomplete functionality with Solr Suggesters, facets and a standard queries]]></description>
										<content:encoded><![CDATA[<p>Its been a long time since the last real blog post here on <a href="http://solr.pl">solr.pl</a>, but better later than ever, right? So, today we will get back to the topic of autocomplete functionality with Solr Suggesters, facets and a standard queries with n-gram approach. So, the same functionality, but done with different approach, depending on the needs and preferences.</p>
<p><span id="more-915"></span></p>
<p>Today we will look at a more sophisticated autocomplete functionality &#8211; one that suggest words with special characters while the user types in words with or without autocomplete.<br />
<!--more--></p>
<h3>Autocomplete With Special Characters</h3>
<p>Imagine we have words documents that have only two fields &#8211; <em>id</em>, which is the document identifier and a <em>name</em>, which is the name of the document and the field on which we would like to run autocomplete on. The <em>name</em> field is the one that can have language based characters, like <em>ż</em>, <em>ć</em> or <em>ę</em> in polish. And we would like to support them for all our users, no matter what type of keyboard they have or what type of locale they have set in their system.</p>
<p>Let&#8217;s assume we have the following documents:
</p>
<pre class="brush:xml">{"id":1, "name":"Pośrednictwo nieruchomości"}
{"id":2, "name":"Posadowienie budynków"}
{"id":3, "name":"Posocznica"}</pre>
<p>The names are not important, the use case is. We would like to be able to get all three documents when the user enters <em>pos</em> into the search box. Is that possible? Yes and let&#8217;s see how.</p>
<h3>Preparing Collection Structure</h3>
<p>Let&#8217;s start with the <em>schema.xml</em> file and the definition of the fields and types. We will completely ignore that search here and only focus on autocomplete. We also assume that we want the whole name to be displayed whenever user input matched any of the terms in the <em>name</em> field.<br />
We will start with the fields, which look like this:
</p>
<pre class="brush:xml">&lt;field name="id" type="int" indexed="true" stored="true" required="true" multiValued="false" /&gt;
&lt;field name="name" type="string" indexed="false" stored="true" multiValued="false" /&gt;
&lt;field name="name_ac" type="text_ac" indexed="true" stored="false" multiValued="false" /&gt;</pre>
<p>So, we will have our <em>id</em> field which is an integer, <em>name</em> field which we will use only for display purposes. The <em>name_ac</em> field will be used for the actual autocomplete. To not bother with manually filling the <em>name_ac</em> field we will use <em>copyField</em> definition in the <em>schema.xml</em>:
</p>
<pre class="brush:xml">&lt;copyField source="name" dest="name_ac" /&gt;</pre>
<p>The <em>name_ac</em> definition will use ngrams for efficient prefix queries and a filter that will remove all the funky, special, language specific characters &#8211; the <em>solr.ASCIIFoldingFilterFactory</em>. We need to do that both during index and during query time, so that both sides of the analysis works. The <em>text_ac </em>type definition looks as follows:
</p>
<pre class="brush:xml">&lt;fieldType name="text_ac" class="solr.TextField" positionIncrementGap="100"&gt;
&nbsp; &lt;analyzer type="index"&gt;
&nbsp;&nbsp;&nbsp; &lt;tokenizer class="solr.KeywordTokenizerFactory"/&gt;
&nbsp;&nbsp;&nbsp; &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
&nbsp;&nbsp;&nbsp; &lt;filter class="solr.ASCIIFoldingFilterFactory"/&gt;
&nbsp;&nbsp;&nbsp; &lt;filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="100" /&gt;
&nbsp; &lt;/analyzer&gt;
&nbsp; &lt;analyzer type="query"&gt;
&nbsp;&nbsp;&nbsp; &lt;tokenizer class="solr.KeywordTokenizerFactory"/&gt;
&nbsp;&nbsp;&nbsp; &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
&nbsp;&nbsp;&nbsp; &lt;filter class="solr.ASCIIFoldingFilterFactory"/&gt;
&nbsp; &lt;/analyzer&gt;
&lt;/fieldType&gt;</pre>
<p>During index time, we lowercase the whole input, remove language specific characters and turn them into ASCII equivalent and finally created edge ngram with the minimum size of 1, which means that the ngram will start from a single letter and will have a maximum size of 100. During query time, we lowercase the whole input and remove language specific characters and that&#8217;s all that is needed.</p>
<h3>Let&#8217;s Test</h3>
<p>To test the changes we will start Solr in the SolrCloud mode with the local ZooKeeper by running the following command from Solr home directory:
</p>
<pre class="brush:xml">$ bin/solr start -c</pre>
<p>Next we will upload the configuration that includes all the changes to ZooKeeper by running the following command:
</p>
<pre class="brush:xml">$ bin/solr zk upconfig -z localhost:9983 -n autocomplete -d /home/config/autocomplete/conf</pre>
<p>The only thing you need to care about for that command to work on your local machine is adjusting the directory with the configuration. The configuration itself can be downloaded from our Github account (<a href="http://autocomplete_with_special_chars/conf/">config download</a>).</p>
<p>Now we need to create the collection by running the following command:
</p>
<pre class="brush:xml">$ curl 'localhost:8983/solr/admin/collections?action=CREATE&amp;name=autocomplete&amp;numShards=1&amp;replicationFactor=1&amp;collection.configName=autocomplete'</pre>
<p>We have everything in place to index our documents, which we can do by running the following command:
</p>
<pre class="brush:xml">$ curl "http://localhost:8983/solr/autocomplete/update?commit=true" -H 'Content-type:application/json' -d '[
&nbsp; {"id":1, "name":"Pośrednictwo nieruchomości"},
&nbsp; {"id":2, "name":"Posadowienie budynków"},
&nbsp; {"id":3, "name":"Posocznica"}
]'</pre>
<p>So now, let&#8217;s run two queries that should tell us if the above method really works. The first query looks as follows:
</p>
<pre class="brush:xml">http://localhost:8983/solr/autocomplete/select?q.op=AND&amp;defType=edismax&amp;qf=name_ac&amp;fl=id,name&amp;q=pos</pre>
<p>The second query looks as follows:
</p>
<pre class="brush:xml">http://localhost:8983/solr/autocomplete/select?q.op=AND&amp;defType=edismax&amp;qf=name_ac&amp;fl=id,name&amp;q=pos</pre>
<p>In both cases we are running a query using the Extended DisMax query parser, we are using <em>AND</em> as the Boolean operator (<em>q.op</em> parameter) and we are saying that we want to run the query on the <em>name_ac</em> field by using the <em>qf</em> parameter. We also say that we only want the <em>id</em> and <em>name</em> field to be returned in the search results by specifying the <em>fl</em> parameter.</p>
<p>The results returned by Solr, in both cases are identical and look as follows:
</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;response&gt;
&lt;lst name="responseHeader"&gt;
&nbsp; &lt;bool name="zkConnected"&gt;true&lt;/bool&gt;
&nbsp; &lt;int name="status"&gt;0&lt;/int&gt;
&nbsp; &lt;int name="QTime"&gt;0&lt;/int&gt;
&nbsp; &lt;lst name="params"&gt;
&nbsp;&nbsp;&nbsp; &lt;str name="q"&gt;poś&lt;/str&gt;
&nbsp;&nbsp;&nbsp; &lt;str name="defType"&gt;edismax&lt;/str&gt;
&nbsp;&nbsp;&nbsp; &lt;str name="qf"&gt;name_ac&lt;/str&gt;
&nbsp;&nbsp;&nbsp; &lt;str name="fl"&gt;id,name&lt;/str&gt;
&nbsp;&nbsp;&nbsp; &lt;str name="q.op"&gt;AND&lt;/str&gt;
&nbsp; &lt;/lst&gt;
&lt;/lst&gt;
&lt;result name="response" numFound="3" start="0"&gt;
&nbsp; &lt;doc&gt;
&nbsp;&nbsp;&nbsp; &lt;int name="id"&gt;1&lt;/int&gt;
&nbsp;&nbsp;&nbsp; &lt;str name="name"&gt;Pośrednictwo nieruchomości&lt;/str&gt;&lt;/doc&gt;
&nbsp; &lt;doc&gt;
&nbsp;&nbsp;&nbsp; &lt;int name="id"&gt;2&lt;/int&gt;
&nbsp;&nbsp;&nbsp; &lt;str name="name"&gt;Posadowienie budynków&lt;/str&gt;&lt;/doc&gt;
&nbsp; &lt;doc&gt;
&nbsp;&nbsp;&nbsp; &lt;int name="id"&gt;3&lt;/int&gt;
&nbsp;&nbsp;&nbsp; &lt;str name="name"&gt;Posocznica&lt;/str&gt;&lt;/doc&gt;
&lt;/result&gt;
&lt;/response&gt;</pre>
<p>So the method works <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/2017/01/29/autocomplete-with-special-characters/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>Autocomplete on multivalued fields using highlighting</title>
		<link>https://solr.pl/en/2013/02/25/autocomplete-on-multivalued-fields-using-highlighting/</link>
					<comments>https://solr.pl/en/2013/02/25/autocomplete-on-multivalued-fields-using-highlighting/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 25 Feb 2013 12:50:33 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[highlighting]]></category>
		<category><![CDATA[multivalued]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=536</guid>

					<description><![CDATA[One of the recent topics I came across was auto complete feature based on Solr multi-valued fields (for example, this question was asked on Stack Overflow). Let&#8217;s look what possibilities we have. Multiple cores vs single core One of the]]></description>
										<content:encoded><![CDATA[<p>One of the recent topics I came across was auto complete feature based on Solr multi-valued fields (for example, this question was asked on <a href="http://stackoverflow.com/questions/14865417/autocomplete-feature-using-solr4-on-multivalued-fields">Stack Overflow</a>). Let&#8217;s look what possibilities we have.</p>
<p><span id="more-536"></span></p>
<h2>Multiple cores vs single core</h2>
<p>One of the possibilities we should consider in the beginning is if we can use a dedicated core or collection for autocomplete. If we can, we should go that way. There are multiple reasons in favor of such approach, for example such collection will be smaller than the one with the data that needs to be search-able, the term count should be smaller and thus your queries will be faster. Of course we have to take care of the additional configuration and indexing, but that&#8217;s not too much of a problem right ? In this entry we will look at the situations where having a separate core is not an option &#8211; for example because of filtering that needs to be done.</p>
<p>Please also note, that in this entry we assume that we want whole phrases to be shown for the user.</p>
<h2>Configuration</h2>
<p>Let&#8217;s start from the configuration.</p>
<h3>Struktura indeksu</h3>
<p>Let&#8217;s assume that we want to suggest phrases from the multi valued fields. Let&#8217;s call that field&nbsp; <em>features</em>. Configuration of all the fields in the index is as follows:
</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>As you can see, for the auto complete feature, we will use the field named <em>features_autocomplete</em>. The <em>_version_</em> field is needed by some of the Solr 4.0 (and newer) features and because of that it is present in our index.</p>
<h3>Field values copying</h3>
<p>In addition to the above configuration we also want to copy the data from the <em>features</em> field to the&nbsp;<em>features_autocomplete</em> one. In order to do that we will use Solr copy field feature. To do that, we add the following section to the <em>schema.xml</em> file:
</p>
<pre class="brush:xml">&lt;copyField source="features" dest="features_autocomplete"/&gt;</pre>
<h3>Field type &#8211; text_autocomplete</h3>
<p>Let&#8217;s have a look at the last thing we have when it comes to configuration &#8211; the definition of the <em>text_autocomplete</em> type:
</p>
<pre class="brush:xml">&lt;fieldType name="text_autocomplete" class="solr.TextField" positionIncrementGap="100"&gt;
 &lt;analyzer type="index"&gt;
  &lt;tokenizer class="solr.KeywordTokenizerFactory"/&gt;
  &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
  &lt;filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="50" /&gt;
 &lt;/analyzer&gt;
 &lt;analyzer type="query"&gt;
  &lt;tokenizer class="solr.KeywordTokenizerFactory" /&gt;
  &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
 &lt;/analyzer&gt;
&lt;/fieldType&gt;</pre>
<p>As you can see, during indexing, Solr will create n-grams from the phrase indexed in the <em>features_autocomplete</em> field. It will start from the minimum length of 2, ending on the maximum length of 50.</p>
<p>During querying we will only lowercase our query phrase, nothing else is needed in our case.</p>
<h3>Sample data</h3>
<p>Our sample data looks like this:
</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>Initial query</h2>
<p>Let&#8217;s look at the queries now.</p>
<h3>In the beginning</h3>
<p>Let&#8217;s start with a simple query that would return the data we need if we would use a single valued fields. The query looks as follows:
</p>
<pre class="brush:xml">q=features_autocomplete:sing&amp;fl=features_autocomplete</pre>
<h3>Query results</h3>
<p>The results we would get from such query, for our example data, should look like this:
</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;3&lt;/int&gt;
  &lt;lst name="params"&gt;
   &lt;str name="fl"&gt;features_autocomplete&lt;/str&gt;
   &lt;str name="q"&gt;features_autocomplete:sing&lt;/str&gt;
  &lt;/lst&gt;
 &lt;/lst&gt;
 &lt;result name="response" numFound="2" start="0"&gt;
 &lt;doc&gt;
  &lt;arr name="features_autocomplete"&gt;
   &lt;str&gt;Single window&lt;/str&gt;
   &lt;str&gt;Single door&lt;/str&gt;
  &lt;/arr&gt;
 &lt;/doc&gt;
 &lt;doc&gt;
  &lt;arr name="features_autocomplete"&gt;
   &lt;str&gt;Multiple windows&lt;/str&gt;
   &lt;str&gt;Single door&lt;/str&gt;
  &lt;/arr&gt;
 &lt;/doc&gt;
 &lt;/result&gt;
&lt;/response&gt;</pre>
<h3>A short comment</h3>
<p>As we can see, the results are not satisfying us, because in addition to the value we are querying for, we got all the values that are stored in the multi-valued field. We would only like to have the one that we queried for. Is this possible ? Yes it is &#8211; with a little trick. Let&#8217;s modify our query to use highlighting.</p>
<h2>Query with highlighting</h2>
<p>So now, we will make use of Apache Solr highlighting module.</p>
<h3>Changed query</h3>
<p>What we will do is add the following part to our previous query:
</p>
<pre class="brush:xml">hl=true&amp;hl.fl=features_autocomplete&amp;hl.simple.pre=&amp;hl.simple.post=</pre>
<p>So the whole query looks like this:
</p>
<pre class="brush:xml">q=features_autocomplete:sing&amp;fl=features_autocomplete&amp;hl=true&amp;hl.fl=features_autocomplete&amp;hl.simple.pre=&amp;hl.simple.post=</pre>
<p>A few words about the parameters that were used:</p>
<ul>
<li><em>hl=true</em> &#8211; we inform Solr that we want to use highlighting,</li>
<li><em>hl.fl=features_autocomplete</em> &#8211; we tell Solr which field should be used for highlighting,</li>
<li><em>hl.simple.pre=</em> &#8211; setting the&nbsp;<em>hl.simple.pre</em> to empty value tells Solr that we don&#8217;t want to mark the beginning of the highlighted fragment,</li>
<li><em>hl.simple.post=</em> &#8211; setting the&nbsp;<em>hl.simple.post</em> to empty value tells Solr that we don&#8217;t want to mark the end of the highlighted fragment.</li>
</ul>
<h3>Modified query results</h3>
<p>After querying Solr with the modified query, the following results were returned:
</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;4&lt;/int&gt;
  &lt;lst name="params"&gt;
   &lt;str name="fl"&gt;features_autocomplete&lt;/str&gt;
   &lt;str name="q"&gt;features_autocomplete:sing&lt;/str&gt;
   &lt;str name="hl.simple.pre"/&gt;
   &lt;str name="hl.simple.post"/&gt;
   &lt;str name="hl.fl"&gt;features_autocomplete&lt;/str&gt;
   &lt;str name="hl"&gt;true&lt;/str&gt;
  &lt;/lst&gt;
 &lt;/lst&gt;
 &lt;result name="response" numFound="2" start="0"&gt;
 &lt;doc&gt;
  &lt;arr name="features_autocomplete"&gt;
   &lt;str&gt;Single window&lt;/str&gt;
   &lt;str&gt;Single door&lt;/str&gt;
  &lt;/arr&gt;
 &lt;/doc&gt;
 &lt;doc&gt;
  &lt;arr name="features_autocomplete"&gt;
   &lt;str&gt;Multiple windows&lt;/str&gt;
   &lt;str&gt;Single door&lt;/str&gt;
  &lt;/arr&gt;
 &lt;/doc&gt;
 &lt;/result&gt;
 &lt;lst name="highlighting"&gt;
  &lt;lst name="2"&gt;
   &lt;arr name="features_autocomplete"&gt;
    &lt;str&gt;Single window&lt;/str&gt;
   &lt;/arr&gt;
  &lt;/lst&gt;
  &lt;lst name="1"&gt;
   &lt;arr name="features_autocomplete"&gt;
    &lt;str&gt;Single door&lt;/str&gt;
   &lt;/arr&gt;
  &lt;/lst&gt;
 &lt;/lst&gt;
&lt;/response&gt;</pre>
<p>As you can see, the section responsible for highlighting brings the information that we are interested in <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>
<h2>Summary</h2>
<p>Of course we need to remember that the approach proposed in this entry is not the only way to have a working auto-complete feature with data in multi-valued fields. In the next entry in this topic we will show how we can use faceting do get the same results if only we can accept some small drawbacks.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2013/02/25/autocomplete-on-multivalued-fields-using-highlighting/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Autcomplete, part 4 (Ngram and faceting)</title>
		<link>https://solr.pl/en/2012/05/28/autcomplete-part-4-ngram-and-faceting/</link>
					<comments>https://solr.pl/en/2012/05/28/autcomplete-part-4-ngram-and-faceting/#respond</comments>
		
		<dc:creator><![CDATA[Marek Rogoziński]]></dc:creator>
		<pubDate>Mon, 28 May 2012 21:47:24 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[autocomplete]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=460</guid>

					<description><![CDATA[In the previous parts of autocomplete series we presented two methods of autocomplete queries. Than we extended one of those with the ability to define returned information. In todays entry we are back to autocomplete with facet and ngram. Requirements]]></description>
										<content:encoded><![CDATA[<p>In the previous parts of autocomplete series we presented two methods of autocomplete queries. Than we extended one of those with the ability to define returned information. In todays entry we are back to autocomplete with facet and ngram.</p>
<p><span id="more-460"></span></p>
<h2>Requirements</h2>
<p align="LEFT">Our autocomplete mechanism has the following requirements:</p>
<ol>
<li>We return whole phrase, not just s single word</li>
<li>Returned phrase can be present multiple times in the index</li>
<li>We want to know the number of results for the returned phrase</li>
<li>Common phrases should be shown higher than the less common ones</li>
<li>Order of words entered by the user doesn&#8217;t matter</li>
</ol>
<h2>Solution</h2>
<p style="text-align: justify;" align="LEFT">Solution given in the first part of the series will not met the requirements because of the first requirement. Of course we could change analysis type, but we wouldn&#8217;t return the whole phrase.</p>
<p style="text-align: justify;" align="LEFT">Solution to the above requirements is the modified faceting method. Instead of searching all the elements and narrowing results with <em>facet.prefix</em> parameter, we can search only for those elements that have the word fragment we are looking for. We don&#8217;t want wildcard query to be used (because of performance) we call ngram&#8217;s for the rescue. This means we need to write the ngrams into the index (of course Solr will do that for us). The obvious flaw is the index size growth, but in this case we can live with that.</p>
<h2 style="text-align: justify;" align="LEFT">Schema.xml</h2>
<p style="text-align: justify;" align="LEFT">We define an additional type:</p>
<pre class="brush:xml">  &lt;fieldType name="text_autocomplete" class="solr.TextField" positionIncrementGap="100"&gt;
    &lt;analyzer type="index"&gt;
      &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
      &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
      &lt;filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" /&gt;
    &lt;/analyzer&gt;
    &lt;analyzer type="query"&gt;
      &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
      &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
    &lt;/analyzer&gt;
  &lt;/fieldType&gt;</pre>
<p align="LEFT">We also define additional fields: one which value we plan to return and one which will be used for searching:</p>
<pre class="brush:xml">&lt;field name="tag_autocomplete" type="text_autocomplete" indexed="true" stored="true" omitNorms="true" omitTermFreqAndPositions="true"/&gt;
&lt;field name="tag" type="string" indexed="true" stored="true" /&gt;</pre>
<p align="LEFT">And one <em>copyField</em> to make things easier:</p>
<pre class="brush:xml">&lt;copyField source="tag" dest="tag_autocomplete"/&gt;</pre>
<h2 class="brush:xml">Query</h2>
<p align="LEFT">After indexation we are ready to test our queries:</p>
<ol>
<li>We are narrowing results, only to those which have the interesting word fragment in the <em>tag_autocomplete</em> field, with: <em>q=tag_autocomplete:(PHRASE)</em></li>
<li>We need all the fragments entered by the user, so we use <em>AND</em> as our logical operator: <em>q.op=AND</em></li>
<li>We not interested in the actual query results, we will use data returned by faceting, so we say: <em>rows=0</em></li>
<li>We need faceting: <em>facet=true</em></li>
<li>We need faceting on the field where we store the original phrase: <em>facet.field=tag</em></li>
<li>We are not interested in empty tags: <em>facet.mincount=1</em></li>
<li>We are only interested in 5 autocomplete values: <em>facet.limit=5</em></li>
</ol>
<p align="LEFT">And the final query:</p>
<pre>?q=tag_autocomplete:(PHRASE)&amp;q.op=AND&amp;rows=0&amp;facet=true&amp;facet.field=tag&amp;facet.mincount=1&amp;facet.limit=5</pre>
<p align="LEFT">If we will configure out search handler to include all the constant parameters, we will have the following query:</p>
<pre>?q=tag_autocomplete:(PHRASE)</pre>
<h2>At the end</h2>
<p align="LEFT">The basic virtue of the presented method is the ability to use one field for searching and other for returning results. Because of that, we were able to return the whole phrase instead of a single word.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2012/05/28/autcomplete-part-4-ngram-and-faceting/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Solr and autocomplete (part 3)</title>
		<link>https://solr.pl/en/2010/11/29/solr-and-autocomplete-part-3/</link>
					<comments>https://solr.pl/en/2010/11/29/solr-and-autocomplete-part-3/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 29 Nov 2010 22:38:55 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[suggest]]></category>
		<category><![CDATA[suggest component]]></category>
		<category><![CDATA[suggester]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=156</guid>

					<description><![CDATA[In the previous parts (part 1, part. 2) of the cycle, we learned how to configure and query Solr to get the autocomplete functionality. In today&#8217;s entry I will show you how to add the dictionary to the Suggester, and]]></description>
										<content:encoded><![CDATA[<p>In  the previous parts (<a href="http://solr.pl/en/2010/10/18/solr-and-autocomplete-part-1/">part 1</a>, <a href="http://solr.pl/en/2010/11/15/solr-and-autocomplete-part-2/">part. 2</a>) of the cycle, we learned how to  configure and query Solr to get the autocomplete functionality. In  today&#8217;s entry I will show you how to add the dictionary to the  Suggester, and thus have an impact on the generated suggestions.</p>
<p><span id="more-156"></span></p>
<p><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"></p>
<h3>Component configuration</h3>
<p>To configure the component presented in the previous part of the cycle add the following parameter:
</p>
<pre class="brush:xml">&lt;str name="sourceLocation"&gt;dict.txt&lt;/str&gt;</pre>
<p>Thus our configuration should look like this:
</p>
<pre class="brush:xml">&lt;searchComponent name="suggest" class="solr.SpellCheckComponent"&gt;
 &lt;lst name="spellchecker"&gt;
  &lt;str name="name"&gt;suggest&lt;/str&gt;
  &lt;str name="classname"&gt;org.apache.solr.spelling.suggest.Suggester&lt;/str&gt;
  &lt;str name="lookupImpl"&gt;org.apache.solr.spelling.suggest.tst.TSTLookup&lt;/str&gt;
  &lt;str name="field"&gt;name_autocomplete&lt;/str&gt;
  &lt;str name="sourceLocation"&gt;dict.txt&lt;/str&gt;
 &lt;/lst&gt;
&lt;/searchComponent&gt;</pre>
<p>With the parameter we informed the component to use the dictionary named <em>dict.txt</em> which should be placed in the Solr configuration directory.</p>
<h3>Handler configuration</h3>
<p>The handler configuration also gets one additional parameter which is:
</p>
<pre class="brush:xml">&lt;str name="spellcheck.onlyMorePopular"&gt;true&lt;/str&gt;</pre>
<p>So our configuration should be as follows:
</p>
<pre class="brush:xml">&lt;requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchComponent"&gt;
 &lt;lst name="defaults"&gt;
  &lt;str name="spellcheck"&gt;true&lt;/str&gt;
  &lt;str name="spellcheck.dictionary"&gt;suggest&lt;/str&gt;
  &lt;str name="spellcheck.count"&gt;10&lt;/str&gt;
  &lt;str name="spellcheck.onlyMorePopular"&gt;true&lt;/str&gt;
 &lt;/lst&gt;
 &lt;arr name="components"&gt;
  &lt;str&gt;suggest&lt;/str&gt;
 &lt;/arr&gt;
&lt;/requestHandler&gt;</pre>
<p>This parameter tell Solr, to return only those suggestions for which the number of results is greater than the number of results for the current query.</p>
<h3>Dictionary</h3>
<p>We told Solr to use the dictionary, but how should this dictionary look like ? For the purpose of this post I defined the following dictionary:
</p>
<pre class="brush:plain"># sample dict
Hard disk hitachi
Hard disk wd    2.0
Hard disk jjdd    3.0</pre>
<p>What is the construction of a dictionary? Each of the phrases (or single words) is located in a separate line. Each  line ends with the weight of the phrase (between the weight and the  phrase is a TAB character) which is used together with the parameter  <em>spellcheck.onlyMorePopular=true</em> (the higher the weight, the higher the  suggestion will be). The default weight value is 1.0. A dictionary should be saved in UTF-8 encoding. Lines beginning with # character are skipped.</p>
<h3>Data</h3>
<p>In this case we don&#8217;t need data &#8211; we will only use the defined dictionary.</p>
<h3>Let&#8217;s check how it works</h3>
<p>To check how our mechanism behaves I sent the following query to Solr, of course after rebuilding of the Suggester index:</p>
<p><code>/suggest?q=Har</code></p>
<p>As a result we get the following:
</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&gt;
&lt;lst name="spellcheck"&gt;
  &lt;lst name="suggestions"&gt;
    &lt;lst name="Dys"&gt;
      &lt;int name="numFound"&gt;3&lt;/int&gt;
      &lt;int name="startOffset"&gt;0&lt;/int&gt;
      &lt;int name="endOffset"&gt;3&lt;/int&gt;
      &lt;arr name="suggestion"&gt;
        &lt;str&gt;Hard disk jjdd&lt;/str&gt;
        &lt;str&gt;Hard disk hitachi&lt;/str&gt;
        &lt;str&gt;Hard disk wd&lt;/str&gt;
     &lt;/arr&gt;
    &lt;/lst&gt;
  &lt;/lst&gt;
&lt;/lst&gt;
&lt;/response&gt;
</pre>
<h3>A few words at the end</h3>
<p>As you can see the suggestions are sorted by on the basis of weight, as expected. It  is worth noting that the query was passed with a capital letter, which  is also important &#8211; the lowercased query will return empty suggestion  list.</p>
<p>What  can you say about the method &#8211; if we have a very good dictionaries  generated on the basis of weights such as customer behavior this is the  method for you and your customers will love it. I  would not recommend it if you don&#8217;t have good dictionaries &#8211; there is a  very high chance that your suggestions will be of poor quality.</p>
<h3>What will be next ?</h3>
<p>The number of tasks this week didn&#8217;t let me finish the performance tests and that&#8217;s why, in the next part of the cycle, I&#8217;ll try to show you how each method behaves with various index structure and size.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2010/11/29/solr-and-autocomplete-part-3/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 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>
	</channel>
</rss>
