error in suggester component in solr

2019-02-16 02:42发布

问题:

I am working with solr auto complete functionality,I am using solr 4.50 to build my application, and I am following this link as a reference. My suggest component is something like this

  <searchComponent class="solr.SpellCheckComponent" name="suggest">
    <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="storeDir">suggest</str>
      <str name="field">autocomplete_text</str>
      <bool name="exactMatchFirst">true</bool>
      <float name="threshold">0.005</float>
      <str name="buildOnCommit">true</str>
      <str name="buildOnOptimize">true</str>
    </lst>
   <lst name="spellchecker">
      <str name="name">jarowinkler</str>  
      <str name="field">lowerfilt</str>  
      <str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>  
      <str name="spellcheckIndexDir">spellchecker</str>  
   </lst>
     <str name="queryAnalyzerFieldType">edgytext</str>  
  </searchComponent>

but, I am getting the following error

org.apache.solr.spelling.suggest.Suggester  – Loading stored lookup data failed
java.io.FileNotFoundException: /home/anurag/Downloads/solr-4.4.0/example/solr/collection1/data/suggest/tst.dat (No such file or directory)

It says that some file are missing but the solr wiki suggester component says it supports these lookupImpls --

<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
      <!-- Alternatives to lookupImpl: 
           org.apache.solr.spelling.suggest.fst.FSTLookup   [finite state automaton]
           org.apache.solr.spelling.suggest.fst.WFSTLookupFactory [weighted finite state automaton]
           org.apache.solr.spelling.suggest.jaspell.JaspellLookup [default, jaspell-based]
           org.apache.solr.spelling.suggest.tst.TSTLookup   [ternary trees]
      -->

Dont know what I am doing wrong..... Any help will be deeply appreciated

回答1:

I was able to get the autosuggest functionality working by using the Solr Term Component

Add term components in your solrconfig.xml like this

<searchComponent name="terms" class="solr.TermsComponent"/>
  <!-- A request handler for demonstrating the terms component -->
  <requestHandler name="/terms" class="solr.SearchHandler" startup="lazy">
     <lst name="defaults">
      <bool name="terms">true</bool>
      <bool name="distrib">false</bool>
    </lst>     
    <arr name="components">
      <str>terms</str>
    </arr>
  </requestHandler>

define a field type for your autosuggest text in schema.xml

    <fieldType name="edgytext" class="solr.TextField" >  
      <analyzer>  
        <tokenizer class="solr.KeywordTokenizerFactory"/>  
        <filter class="solr.LowerCaseFilterFactory"/>  
      </analyzer>  
    </fieldType>

add fields in schema.xml like this

   <field name="name"  type="edgytext" indexed="true" stored="true" />  

   <field name="autocomplete_text" type="edgytext" indexed="true" stored="false"  multiValued="true" omitNorms="true" omitTermFreqAndPositions="false" />

   <copyField source="name" dest="autocomplete_text"/>

Now the most important step... Remove all the folders from your index directory (can be found in solrconfig.xml ,.. look for <dataDir> tag)

Restart the solr. and reindex your data. You will se new folders created in your index directory.

You can check the auto suggest working by hitting the url -

http://127.0.0.1:8983/solr/your_core/terms?terms.fl=autocomplete_text&omitHeader=true&terms.limit=20&terms.sort=index&terms.regex=(.*)your_query(.*)