Solr auto complete

来源:互联网 发布:网络游戏服务器端编程 编辑:程序博客网 时间:2024/05/02 15:35

Suggester - a flexible "autocomplete" component.


http://wiki.apache.org/solr/Suggester


要用solr实现类似谷歌 autocomplete功能,并不是那么容易,关键还是要看怎么分词。

下面是设置的一个简单例子:2014 Chevrolet Silverado


 <searchComponent class="solr.SpellCheckComponent" name="suggest">
      <!-- configure the spellchecker used
         for autocomplete (dictionary) -->
      <lst name="spellchecker">
          <str name="name">suggester_dictionary</str>
          <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
          <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.FSTLookupFactory</str>
          <!-- The indexed field to derive suggestions from -->
          <str name="field">autocomplete</str>
          <!-- buildOnCommit must be set to true because
            suggester keeps data in memory -->
          <str name="buildOnCommit">true</str>
      </lst>
  </searchComponent>



<requestHandler class="solr.SearchHandler" name="/suggest">
      <lst name="defaults">
          <!-- by default use the suggester_dictionary -->
          <str name="spellcheck.dictionary">suggester_dictionary</str>
          <str name="spellcheck.count">5</str>
          <str name="spellcheck.onlyMorePopular">false</str>
      </lst>
      <lst name="invariants">
          <!-- always run the Suggester for queries to this handler -->
          <str name="spellcheck">true</str>
          <!-- collate not needed, query if tokenized as keyword, we need only suggestions for that term -->
          <str name="spellcheck.collate">false</str>
      </lst>
      <!-- this handler uses only the needed component :
        suggest defined above -->
      <arr name="components">
          <str>suggest</str>
      </arr>
  </requestHandler>
原创粉丝点击