如何在 solr 搜索组件中添加多个建议者定义

How to add multiple suggesters definition in solr search components

我正在使用 solr 5.1。我正在尝试根据 Apache solr wiki.

在 Solr 搜索组件中配置多个建议定义

我已经完美地配置了单个建议器并且它工作得很好但是每当我尝试配置多个建议器时它给我以下错误

java.lang.NullPointerException
    at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:190)
    at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:143)
    at org.apache.solr.core.SolrCore.execute(SolrCore.java:1984)
    at org.apache.solr.core.QuerySenderListener.newSearcher(QuerySenderListener.java:64)
    at org.apache.solr.core.SolrCore.call(SolrCore.java:1751)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)


org.apache.lucene.store.AlreadyClosedException: this Directory is closed
    at org.apache.lucene.store.BaseDirectory.ensureOpen(BaseDirectory.java:50)
    at org.apache.lucene.store.FSDirectory.getDirectory(FSDirectory.java:244)
    at org.apache.lucene.store.NativeFSLockFactory.makeFSLock(NativeFSLockFactory.java:85)
    at org.apache.lucene.store.FSLockFactory.makeLock(FSLockFactory.java:39)
    at org.apache.lucene.store.BaseDirectory.makeLock(BaseDirectory.java:44)
    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:774)
    at org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester.build(AnalyzingInfixSuggester.java:296)
    at org.apache.lucene.search.suggest.Lookup.build(Lookup.java:193)
    at org.apache.solr.spelling.suggest.SolrSuggester.build(SolrSuggester.java:163)
    at org.apache.solr.handler.component.SuggestComponent$SuggesterListener.buildSuggesterIndex(SuggestComponent.java:524)
    at org.apache.solr.handler.component.SuggestComponent$SuggesterListener.newSearcher(SuggestComponent.java:506)
    at org.apache.solr.core.SolrCore.call(SolrCore.java:1751)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

org.apache.solr.common.SolrException
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:885)
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:652)
    at org.apache.solr.core.CoreContainer.create(CoreContainer.java:518)
    at org.apache.solr.core.CoreContainer.call(CoreContainer.java:283)
    at org.apache.solr.core.CoreContainer.call(CoreContainer.java:277)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException
    at org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory.create(AnalyzingInfixLookupFactory.java:138)
    at org.apache.solr.spelling.suggest.SolrSuggester.init(SolrSuggester.java:107)
    at org.apache.solr.handler.component.SuggestComponent.inform(SuggestComponent.java:119)
    at org.apache.solr.core.SolrResourceLoader.inform(SolrResourceLoader.java:620)
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:868)
    ... 8 more

以下是我的solrconfig.xml

<searchComponent class="solr.SuggestComponent" name="suggest">
  <lst name="suggester">
    <str name="name">suggest</str>
    <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory</str>
    <str name="dictionaryImpl">org.apache.solr.spelling.suggest.DocumentDictionaryFactory</str>
    <str name="suggestAnalyzerFieldType">suggestAnalyzer</str>
    <str name="queryAnalyzerFieldType">tokenAnalyzer</str>
    <str name="field">suggest_Name</str>  <!-- the indexed field to derive suggestions from -->
    <str name="buildOnCommit">true</str>
  </lst>
  <lst name="suggester">
    <str name="name">suggest2</str>
    <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory</str>
    <str name="dictionaryImpl">org.apache.solr.spelling.suggest.DocumentDictionaryFactory</str>
    <str name="suggestAnalyzerFieldType">suggestAnalyzer</str>
    <str name="queryAnalyzerFieldType">tokenAnalyzer</str>
    <str name="field">suggest_Manu</str>  <!-- the indexed field to derive suggestions from -->
    <str name="buildOnCommit">true</str>
  </lst>
</searchComponent>

<requestHandler class="solr.SearchHandler" name="/suggest">
  <lst name="defaults">
    <str name="spellcheck">true</str>
    <str name="suggest">true</str>
    <str name="suggest.dictionary">suggest</str>
    <str name="suggest.dictionary">suggest2</str>
    <str name="spellcheck.onlyMorePopular">true</str>
    <str name="spellcheck.count">5</str>
    <str name="spellcheck.collate">true</str>
  </lst>
  <arr name="components">
    <str>suggest</str>
  </arr>
</requestHandler>

在你的 solrconfig.xml 两个建议中 lookupImpl 参数是 org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory

<str
 name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory</str>

尝试将 suggester2 lookupImpl 更改为

FuzzyLookupFactory

<str
name="lookupImpl">org.apache.solr.spelling.suggest.fst.FuzzyLookupFactory</str>

感谢您的回答@Dhanesh S Radhakrishnar,您是对的,但实际上我们正在将 AnalyzingInfixLookupFactory 更改为 FuzzyLookupFactory,这有效但我们的目的已经丢失。无论如何我找到了解决方案,问题是,我们需要在第二个建议者的实现中添加分析器的 indexPath。 :)

<searchComponent class="solr.SuggestComponent" name="suggest">
  <lst name="suggester">
    <str name="name">mySuggester</str>
    <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
    <str name="dictionaryImpl">DocumentDictionaryFactory</str>
    <str name="field">suggest_Manu</str>  <!-- the indexed field to derive suggestions from -->
    <str name="weightField">productId_meter</str>
    <str name="suggestAnalyzerFieldType">suggestAnalyzer</str>
    <str name="buildOnCommit">true</str>

  </lst>


  <lst name="suggester">

    <str name="name">mySuggester2</str>
    <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
    <str name="dictionaryImpl">DocumentDictionaryFactory</str>
    <str name="field">suggest_Name</str>  <!-- the indexed field to derive suggestions from -->
    <str name="weightExpression">productId_meter</str>
    <str name="suggestAnalyzerFieldType">suggestAnalyzer</str>
    <str name="indexPath">path-of-system-dir/newSuggester2</str>
    <str name="buildOnCommit">true</str>

  </lst>

</searchComponent>