(9) solr implements the autocomplete Function

Source: Internet
Author: User
Tags solr

What do you believe in autocomplete? If you really don't know it, ask Baidu.

Directly configure

Schema. xml

 <field name="id"     type="string"   indexed="true"  stored="true"  required="true"/> <field name="title" type="text" indexed="true" stored="true"/>

Type Definition:

   <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true"/>   <fieldtype name="text" class="solr.TextField">    <analyzer>        <tokenizer class="solr.WhitespaceTokenizerFactory"/>        <filter class="solr.LowerCaseFilterFactory"/>    </analyzer>

Solrconfig. xml

<searchComponent class="solr.SpellCheckComponent" name="suggester">    <lst name="spellchecker">    <str name="name">suggester</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">title</str>    <float name="threshold">0.01</float>    <str name="buildOnCommit">true</str>    </lst></searchComponent><requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggester">    <lst name="defaults">    <str name="spellcheck">true</str>    <str name="spellcheck.dictionary">suggester</str>    <str name="spellcheck.count">10</str>    </lst>    <arr name="components">    <str>suggester</str>    </arr></requestHandler>

The test result is as follows:

Http: // localhost: 8983/solr/suggester /? Q = % E8 % BF % 99% E6 % 98% AF

<? 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 = "this is"> <int name = "numFound"> 2 </int> <int name = "startOffset"> 0 </int> <int name = "endOffset"> 2 </int> <arr name = "suggestion"> <str> what is the title? </ str> <str> This is a test article </str> </arr> </lst> </response>

For more information, see:

Http://wiki.apache.org/solr/Suggester? Highlight = % 28 autocomplete % 29

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.