from :http://www.cnblogs.com/ibook360/archive/2011/11/30/2269126.html

In the first two parts (part1、part2) in , We learned how to configure and query solr To get the autocomplete function . today , Let's see if it's suggester Add fields , In this way to provide automatic completion function . 

Component configuration  
Add the following parameters to the configuration component in the previous issue :

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

So 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>

Use this parameter , We let suggest The component is called dict.txt As a document of solr Configuration dictionary for .

handler To configure  
handler You also need to add an additional parameter to the configuration of :

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

The complete configuration is :

<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 us solr, When the number of query results is more than the set count Number of hours , Go back to those with more hits .

Dictionary 
We tell solr To use this field , So what does this field look like ? Here's an example :

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

What is the result of this dictionary ? Put each phrase on a separate line , Each line ends with the weight of the phrase ( Between the weight and the phrase is TAB Character separation ), This weight is related to spellcheck.onlyMorePopular=true  Hong Kong's parameters , The default value is 1.0. The field must be in UTF-8 The encoding format of storage . Before each line is # Characters will be ignored ( Comment row ).

data  
In this way , We don't need data , Fields are data .

function  
Rebuilding suggester after , Let's take a look at how it works , Enter the command :

/suggest?q=Har

The result is zero :

<?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 The results are sorted by weight . The case sensitivity here ( Pay attention to the initials ).

What do you suggest ? If we have a good dictionary , The weight of the dictionary is based on the user's query behavior , Then users will definitely like it ! If there is no good dictionary , It's better not to use this way .

next step  
Next issue , Let's take a look at the different ways of suggest The resulting index structure and size .

original text URL:http://java.dzone.com/news/solr-and-autocomplete-part-3?mz=33057-solr_lucene

Reprint :Solr The implementation of autocomplete ( The third part :Suggester The way continued ) More articles about

  1. html( Commonly used labels , Label classification ), Page template , CSS(css Three ways to introduce ), Priority of the three methods of introduction

    HTML Markup language is a non programming language responsible for completing the structure of the page form : label : By <> The package begins with a letter , You can combine legal characters ( -| Numbers ), Special symbols that can be parsed by browsers , The label has a beginning and an end Instructions : By <> package ...

  2. 【 Reprint 】 Be sure to use selenium The waiting for , There are three ways to wait

    Reprinted address :http://blog.csdn.net/huilan_same/article/details/52544521, Thank you for your blog , To study the original text : Too many people can't wait , Bloggers can't help giving ...

  3. Reprint :Solr The implementation of autocomplete ( The second part :Suggester The way )

    from :http://www.cnblogs.com/ibook360/archive/2011/11/30/2269077.html stay Solr Automatic completion of / Introduction to the implementation of automatic supplement ( The first part )  I introduced how to ...

  4. centos shell Programming 4【 Distribution system 】 Server Standardization mkpasswd Tools for generating passwords expect Explain expect Pass parameters expect Automatically synchronize files expect Appoint host And the files you want to synchronize expect File distribution system expect Automatically send key scripts Linux Script execution Lesson 38

    centos shell Programming 4[ Distribution system ] Server Standardization  mkpasswd Tools for generating passwords  expect Explain   expect Pass parameters   expect Automatically synchronize files  expect Appoint host He Yao ...

  5. Linux footstone 【 Second articles 】 Three connection modes of virtual network ( Reprint )

    Install it on the virtual machine Centos After the system , Start configuring static IP, In order to access the virtual machine on the host computer , In a zigzag configuration , I learned that there are three ways to connect virtual machines :Bridged,NAT and Host-only, therefore , I have a new round of all kinds of ...

  6. 【 Reprint 】Redis Of Java client Jedis There are eight ways to call ( Business 、 The Conduit 、 Distributed …) Introduce

    Reprinted address :http://blog.csdn.net/truong/article/details/46711045 keyword :Redis Of Java client Jedis There are eight ways to call ( Business . The Conduit . Distributed …) Medium ...

  7. Through three DEMO Learn to SignalR There are three ways to realize it Reprint https://www.cnblogs.com/zuowj/p/5674615.html

    One . understand SignalR ASP .NET SignalR It's a ASP .NET The class library , Can be in ASP .NET Of Web Real time communication in the project ( namely : client (Web page ) And the server can notify each other in real time ...

  8. spring-boot There are three ways to start [z]

    https://blog.csdn.net/u011425751/article/details/79507386 I haven't blogged for a while , Also in the effort from the traditional stand-alone development to the distributed system transition , So take some notes again , ...

  9. spring-boot There are three ways to start

    spring-boot There are three main ways to start : 1. Run with main Method class 2. From the command line java -jar The way 3. adopt spring-boot-plugin The way One . Execution with main Method ...

  10. Through three DEMO Learn to SignalR There are three ways to realize it

    One . understand SignalR ASP .NET SignalR It's a ASP .NET The class library , Can be in ASP .NET Of Web Real time communication in the project ( namely : client (Web page ) And the server can notify each other in real time ...

Random recommendation

  1. java 22 - 18 The multithreading Thread state transition 、 Thread group

    Diagram of thread state transition : picture Thread groups of threads : Thread group : Putting multiple threads together .     It can classify and manage a batch of threads ,Java Allows the program to control the thread group directly . First create a Runnable Implementation class of publi ...

  2. easyUI-combobox Background import Json Method of data

    One . Foreground page : <input id="List" class="easyui-combobox" data-options="valueFiel ...

  3. 【 Reprint 】Fiddler Introduction to the use of tools ( One )

    original text https://www.cnblogs.com/miantest/p/7289694.html( One ) https://www.cnblogs.com/miantest/p/7290176.html ...

  4. Nine 、 Using multithreading ——NSThread,GCD and NSOperation

    summary Get up in the morning , You turn on the washing machine first , Then use hot water to soak the noodles , Then turn on the computer and start a day's code farming life . among “ Wash the clothes ”.“ Bubble noodles ” and “ Code code ”3 A mission ( Threads ) At the same time , This is multithreading . There are many classic explanations about multithreading on the Internet , here ...

  5. 【 Line segment tree 】Mayor&#39;s posters

    [poj2528]Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 66154   Accept ...

  6. Linux Boot up and boot up

    Linux Boot program details Let's assume that you are familiar with the boot process of other operating systems , Understand the hardware self-test boot steps , Just from Linux Boot loader for the operating system ( For personal computers, it's usually LILO) Start , Introduce Linux Boot steps ...

  7. linux The foundation of the system ---RPM management ( be based on centos7.4)

  8. SQL2008R2 Clear the log

    SQLSERVER2008 Previous versions of SQL sentence : DUMP TRAN Database name WITH NO_LOG SQLSERVER2008-R2 Version execution SQL sentence : ALTER DATABASE database ...

  9. Excerpt from 《Linux And unix shell Programming Guide 》

    shift After operation ,$# And then decrease : If you need to know the last parameter entered on the command line ( It's usually a file name ), There are two options : Use command eval echo \$$#; Use shift command :shift 'expr $# - ...

  10. 3.12 Use... In calculations and comparisons NULL value

    problem :NULL A value will never equal or not equal any value , Also include NULL It's worth it , But we need to calculate the return value of the nullable column just like the real value . for example , Need to be in table emp We found out all of them “WARD” Royalty (COMM) Low cost employees , Put forward to be NULL( empty ...