2013-01-07 41 views
1

我正在使用SolrNet在幾個表格上進行索引和搜索。如何使用solr中的Suggester組件配置自動建議?

我可以成功搜索完整的單詞。

現在,我試圖實現autosuggest功能,其中,查詢將有一個部分單詞或短語,而不是一個完整的單詞。

我Schema.xml的看起來像這樣

<fields> 
    <!-- declare fields of entity class --> 
    <!-- type will specify the table name --> 
    <field name="type" type="string" indexed="true" stored="true" /> 

    <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
    <field name="name" type="text_general" indexed="true" stored="true" omitNorms="true"/> 

    <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/> 
    <field name="_version_" type="long" indexed="true" stored="true"/> 

    <!-- unique field --> 
    <field name="uid" type="uuid" indexed="true" stored="true" /> 

    </fields> 

    <uniqueKey>uid</uniqueKey> 

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

    <types> 
    <fieldType name="uuid" class="solr.UUIDField" indexed="true" /> 
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" /> 
    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/> 

    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/> 
    ..... 
    </types> 

而且我solrconfig.xml中看起來像

<searchComponent name="suggest" class="solr.SpellCheckComponent"> 
    <!-- a spellchecker built from a field of the main index --> 
    <lst name="spellchecker"> 
     <str name="name">suggest</str> 
     <str name="field">name</str> 
     <str name="classname">org.apache.solr.spelling.suggest.Suggester</str> 
     <str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str> 
     <str name="buildOnCommit">true</str>   
     <str name="distanceMeasure">internal</str> 
     <float name="accuracy">0.5</float> 
     <int name="maxEdits">2</int> 
     int name="minPrefix">1</int> 
     <int name="maxInspections">5</int> 
     <int name="minQueryLength">4</int> 
     <float name="maxQueryFrequency">0.01</float> 
     <float name="thresholdTokenFrequency">.01</float>  
    </lst> 

    <!-- a spellchecker that can break or combine words. See "/spell" handler below for usage --> 
    <lst name="spellchecker"> 
     <str name="name">wordbreak</str> 
     <str name="classname">solr.WordBreakSolrSpellChecker</str> 
     <str name="field">name</str> 
     <str name="combineWords">true</str> 
     <str name="breakWords">true</str> 
     <int name="maxChanges">10</int> 
    </lst> 
</searchComponent> 

<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy"> 
    <lst name="defaults"> 
     <str name="df">text</str> 
     <!-- Solr will use suggestions from both the 'default' spellchecker 
      and from the 'wordbreak' spellchecker and combine them. 
      collations (re-written queries) can include a combination of 
      corrections from both spellcheckers --> 
     <str name="spellcheck">true</str> 
     <str name="spellcheck.dictionary">suggest</str> 
     <!--<str name="spellcheck.dictionary">wordbreak</str>--> 
     <str name="spellcheck">on</str> 
     <str name="spellcheck.extendedResults">true</str>  
     <str name="spellcheck.count">10</str> 
     <str name="spellcheck.alternativeTermCount">5</str> 
     <str name="spellcheck.maxResultsForSuggest">5</str>  
     <str name="spellcheck.collate">true</str> 
     <str name="spellcheck.collateExtendedResults">true</str> 
     <str name="spellcheck.maxCollationTries">10</str> 
     <str name="spellcheck.maxCollations">5</str>   
    </lst> 
    <arr name="last-components"> 
     <str>spellcheck</str> 
    </arr> 
    </requestHandler> 

不過,我不是在尋找的輸出得到任何記錄。

請幫忙。

感謝

+0

好奇 - 爲什麼文字多值的,而名字是不是? –

回答

2

你缺少你minPrefix標籤< solrconfig.xml中

<int name="maxEdits">2</int> 
int name="minPrefix">1</int> 
<int name="maxInspections">5</int> 
相關問題