<?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>component &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/component-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://solr.pl/en/</link>
	<description>All things to be found - Blog related to Apache Solr &#38; Lucene projects - https://solr.apache.org</description>
	<lastBuildDate>Tue, 10 Nov 2020 22:39:44 +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>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>
	</channel>
</rss>
