SOLR's Automatic completion implementation method (Part 3: suggester method continued)

Source: Internet
Author: User
Tags solr

In the previous two parts (Part1 and Part2), we learned how to configure and query SOLR to obtain the auto-complete function. Today, let's take a look at how to add fields to suggester to provide automatic completion.
 

Component Configuration 
Add the following parameters to the Configuration component of the previous phase:

<str name="sourceLocation">dict.txt</str>  

In this way, our configuration becomes:

<searchComponent name="suggest" class="solr.SpellCheckComponent">   
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<str name="field">name_autocomplete</str>
<str name="sourceLocation">dict.txt</str>
</lst>
</searchComponent>

In this example, suggestgroup uses the file named dict.txt as the SOLR configuration dictionary.


HandlerConfiguration 
The handler configuration also requires an additional parameter:

<str name="spellcheck.onlyMorePopular">true</str>  

 

Complete Configuration:

<requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchComponent">   
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.onlyMorePopular">true</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>

This parameter tells SOLR that when the number of query results exceeds the set count, more clicks are returned.


Dictionary 
We told SOLR to use this field. What is the length of this field? Here is an example:

# sample dict 
Hard disk hitachi
Hard disk wd 2.0
Hard disk jjdd 3.0


What is the result of this dictionary? Each phrase is placed in a separate line, and each line ends with the weight of the modified phrase (the weight and the phrase are separated by TAB characters ).Spellcheck. onlymorepopular = trueThe default value of the parameter in Hong Kong is 1.0. This field must be stored in the encoding format of the UTF-8. # Characters before each line will be ignored (comment rows ).

Data 
In this way, we do not need data. fields are data.

Run 
After building suggester again, let's take a look at its running status and enter the following command:

/suggest?q=Har

The result is as follows:

<?xml version="1.0" encoding="UTF-8"?>   
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
</lst>
<lst name="spellcheck">
<lst name="suggestions">
<lst name="Dys">
<int name="numFound">3</int>
<int name="startOffset">0</int>
<int name="endOffset">3</int>
<arr name="suggestion">
<str>Hard disk jjdd</str>
<str>Hard disk wd</str>
<str>Hard disk hitachi</str>
</arr>
</lst>
</lst>
</lst>
</response>

 

Conclusion 
As expected, suggest results are sorted by weight. The case sensitivity here (note the first letter ).

What suggestions do you have? If we have a good dictionary, the weight of this dictionary is generated based on the user's query behavior, then the user will certainly like it! If you do not have a good dictionary, do not use this method.

Next step 
In the next issue, let's take a look at the index structure and size produced by suggest in different ways.

Original URL: http://java.dzone.com/news/solr-and-autocomplete-part-3? MZ = 33057-solr_lucene


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.