Solr智能提示autosuggest

solr的智能提示autosuggest是需要依赖spell-check组件的,但是autosuggest和spell-check又是有区别的,下面的内容是从《solr in action》摘抄下来的。

spell-check是在10.1章中讲解的,spell-check的功能就是对你输入的词进行拼写检查,也会配置相应的词典库,并且会进行select搜索,并提示“你是不是要搜索......”等。

spell-check是内置在select的requestHadnler中的,而autosuggest是可以配置自己的requestHandler,就像我们自己配置的/suggest请求处理器,这也是两者之间的不同。

Solr智能提示autosuggest_第1张图片


Solr智能提示autosuggest_第2张图片

                          在这一节,我们通过内建的Solr Suggester为solrpedia构建一个autosuggest的解决方案。一开始,我们需要定义一个指定的request handler 来生成提示。在前面一节中,我们将spell-checking 内置到默认的/select的请求处理器中,但是这种方式不是最好的解决智能提示的方法。第一,在我们的/select处理器中,我们不需要spell-checking的支持。另外,我们不需要其他内置的组件,比如query,facets,highlighting。Solr的结构设计可以使你定义自己的request handlers来避免一个简单的接口背后是一个复杂的实现,就像面向对象那样。

Solr智能提示autosuggest_第3张图片


Solr智能提示autosuggest_第4张图片


Solr智能提示autosuggest_第5张图片


Solr智能提示autosuggest_第6张图片


Solr智能提示autosuggest_第7张图片


Solr智能提示autosuggest_第8张图片

10.3章及10.4章研究的是autosuggest提示列表的排序功能,因为在自己的项目中没有用到,所以还没有细细研究。


下面是我的Solr引擎中的配置

 <requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchHandler">    
    <lst name="defaults">    
        <str name="echoParams">none</str>
	<str name="wt">json</str> <!--显示格式-->
	<str name="indent">false</str>
	<str name="spellcheck">true</str>
        <str name="spellcheck.dictionary">suggestDictionary</str>  <!--Identify the dictionary to use for suggestions-->   
        <str name="spellcheck.onlyMorePopular">true</str>
	<str name="spellcheck.count">100</str>  <!--Specifies the maximum number (integer) of suggestions to provide-->
        <str name="spellcheck.collate">false</str>  <!--这个是spell-check用到的,在我们这里不需要打开,因此false-->
    </lst>    
    <arr name="components">    <!--Override the built-in component pipeline-->
        <str>suggest</str>    <!--Execute the suggest component-->
    </arr>    
  </requestHandler>
  <searchComponent name="suggest" class="solr.SpellCheckComponent">  
    <str name="queryAnalyzerFieldType">string</str>  
    <lst name="spellchecker">    
        <str name="name">suggestDictionary</str>    <!--Name the Suggester dictionary-->
        <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>    
        <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.FSTLookupFactory</str> <!--Lookup implementation class-->   
        <str name="field">authname</str>  <!--Based on the suggest field-->
        <float name="threshold">0.0001</float>  
        <str name="comparatorClass">freq</str>  
        <str name="buildOnOptimize">true</str>  
        <str name="buildOnCommit">true</str> <!--Rebuild the lookup data structure after every commit-->      
    </lst>    
  </searchComponent>


 

你可能感兴趣的:(Solr智能提示autosuggest)