How to add multiple suggesters definition in solr search components

旧巷老猫 提交于 2019-12-11 20:31:32

问题


I am using solr 5.1. I am trying to configure multiple suggester definition in Solr search component according to Apache solr wiki.

I have configured single suggester perfectly and it works perfect but whenever I try to configure multiple suggester it gives me following errors

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$5.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$5.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$1.call(CoreContainer.java:283)
    at org.apache.solr.core.CoreContainer$1.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

Following is my 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>

回答1:


In your solrconfig.xml both suggesters lookupImpl parameter is org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory

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

Try to change the suggester2 lookupImpl with

FuzzyLookupFactory

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



回答2:


Thanks for your answer @Dhanesh S Radhakrishnar, You are right but then we are actually changing the AnalyzingInfixLookupFactory to FuzzyLookupFactory which works but our purpose has been lost. Anyhow i have found the solution and the thing is that, we need to add the indexPath of analyzer in the implementation of second suggester. :)

<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>


来源:https://stackoverflow.com/questions/30602661/how-to-add-multiple-suggesters-definition-in-solr-search-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!