首页 > 代码库 > Solr Suggest 配置

Solr Suggest 配置

1.配置

<searchComponent  name="suggest" class="solr.SpellCheckComponent">

    <str name="queryAnalyzerFieldType">string</str>

    <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="field">text</str>

        <float name="threshold">0.0001</float>

        <str name="spellcheckIndexDir">spellchecker</str>

        <str name="comparatorClass">freq</str>

        <str name="buildOnOptimize">true</str>

        <!--<str name="buildOnCommit">true</str>-->

    </lst>

</searchComponent>

<requestHandler  name="/suggest" class="solr.SearchHandler" startup="lazy">

    <lst name="defaults">

        <str name="spellcheck">true</str>

        <str name="spellcheck.dictionary">suggest</str>

        <str name="spellcheck.onlyMorePopular">true</str>

        <str name="spellcheck.extendedResults">false</str>

        <str name="spellcheck.count">10</str>

        <str name="spellcheck.collate">true</str>

    </lst>

    <arr name="components">

        <str>suggest</str>

    </arr>

 </requestHandler>

 
 
/suggest?q=....
 
public JsonResult SolrSuggest(string text)
        {
            List<string> list=new List<string>();
            var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
            var results = solr.Query(text, new QueryOptions()
            {
                SpellCheck = new SpellCheckingParameters(){Collate = true}
            });
            foreach (var item in results.SpellChecking)
            {
                foreach (var sc in item.Suggestions)
                {
                    list.Add(sc);
                }
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }