java - Solr 所有检查器需要使用相同的分析器

标签 java solr

我正在尝试对一些索引数据运行拼写检查。我最初想出如何去做,但我弄乱了一些配置,现在它说“所有检查器都需要使用相同的分析器。”我读到这是因为“字段”值被命名为不同的东西。我已经拼写了所有的拼写检查组件。我还做错了什么。

当我输入 is 时出现错误

http://localhost:8080/solr/collection1/select?q=name%3Adoc&wt=json&indent=true&spellcheck=true&spellcheck.collate=true&spellcheck.build=true

我的 solrconfig.xml


<requestHandler name="/select" class="solr.SearchHandler">

    <lst name="defaults">
        <!-- Optional, must match spell checker's name as defined above, defaults to "default" -->
        <str name="spellcheck.dictionary">default</str>
        <!-- Also generate Word Break Suggestions (Solr 4.0 see SOLR-2993) -->
        <str name="spellcheck.dictionary">wordbreak</str>
        <!-- omp = Only More Popular -->
        <str name="spellcheck.onlyMorePopular">false</str>
        <!-- exr = Extended Results -->
        <str name="spellcheck.extendedResults">false</str>
        <!--  The number of suggestions to return -->
        <str name="spellcheck.count">10</str>
    </lst>
    <arr name="last-components">
        <str>spellcheck</str>
    </arr>

</requestHandler>

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
    <lst name="spellchecker">

        <str name="name">default</str>
        <!-- The classname is optional, defaults to IndexBasedSpellChecker -->
        <str name="classname">solr.IndexBasedSpellChecker</str>

        <str name="field">spell</str>
        <!-- Optional, by default use in-memory index (RAMDirectory) -->
        <str name="spellcheckIndexDir">./spellchecker</str>
        <!-- Set the accuracy (float) to be used for the suggestions. Default is 0.5 -->
        <str name="accuracy">0.7</str>
        <!-- Require terms to occur in 1/100th of 1% of documents in order to be included in the   dictionary -->
        <float name="thresholdTokenFrequency">.0001</float>
    </lst>
    <!-- a spellchecker that can break or combine words. (Solr 4.0 see SOLR-2993) -->
    <lst name="spellchecker">
        <str name="name">wordbreak</str>
        <str name="classname">solr.WordBreakSolrSpellChecker</str>
        <str name="field">spell</str>
        <str name="combineWords">true</str>
        <str name="breakWords">true</str>
        <int name="maxChanges">3</int>
    </lst>
    <!-- Example of using different distance measure -->
    <lst name="spellchecker">
        <str name="name">jarowinkler</str>
        <str name="field">spell</str>
        <!--  Use a different Distance Measure -->
        <str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>
        <str name="spellcheckIndexDir">./spellchecker</str>
    </lst>

    <!-- This field type's analyzer is used by the QueryConverter to tokenize the value for "q" parameter -->
    <str name="queryAnalyzerFieldType">textSpell</str>
</searchComponent>


<searchComponent class="solr.SpellCheckComponent" name="suggest">
    <lst name="spellchecker">
        <str name="name">spell</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">suggest</str>
        <float name="threshold">0.005</float>
        <str name="buildOnCommit">true</str>

    </lst>

</searchComponent>
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
    <lst name="defaults">
        <str name="spellcheck">true</str>
        <str name="spellcheck.dictionary">suggest</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>

我的 schema.xml

<field name="id" type="string" indexed="true" stored="true" required="true"  multiValued="false" />
<field name="sku" type="text_en_splitting_tight" indexed="true" stored="true" omitNorms="true"/>
<field name="name" type="text_general" indexed="true" stored="true"/>
<field name="manu" type="text_general" indexed="true" stored="true" omitNorms="true"/>
<field name="cat" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="features" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="includes" type="text_general" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" />

<field name="weight" type="float" indexed="true" stored="true"/>
<field name="price"  type="float" indexed="true" stored="true"/>
<field name="popularity" type="int" indexed="true" stored="true" />
<field name="inStock" type="boolean" indexed="true" stored="true" />

<field name="store" type="location" indexed="true" stored="true"/>

堆栈跟踪

    java.lang.IllegalArgumentException: All checkers need to use the 
    same Analyzer.\n\tat org.apache.solr.spelling.ConjunctionSolrSpellChecker.addChecker(
    ConjunctionSolrSpellChecker.java:79)\n\tat org.apache.
    solr.handler.component.SpellCheckComponent.getSpellChecker(SpellCheckComponent.java:501)
    \n\tat org.apache.solr.handler.component.SpellCheckComponent.prepare(SpellCheckComponent.
    java:122)\n\tat org.apache.solr.handler.component.SearchHandler.handleRequestBody
    (SearchHandler.java:187)\n\tat org.apache.solr.handler.RequestHandlerBase.handleRequest
    (RequestHandlerBase.java:135)\n\tat org.apache.solr.core.SolrCore.execute
    (SolrCore.java:1904)\n\tat org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:659)
    \n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter
    (SolrDispatchFilter.java:362)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter
    (SolrDispatchFilter.java:158)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
    (ApplicationFilterChain.java:243)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter
    (ApplicationFilterChain.java:210)\n\tat org.apache.catalina.core.StandardWrapperValve.invoke
    (StandardWrapperValve.java:222)\n\tat org.apache.catalina.core.StandardContextValve.invoke
    (StandardContextValve.java:123)\n\tat org.apache.catalina.core.StandardHostValve.invoke
    (StandardHostValve.java:171)\n\tat org.apache.catalina.valves.ErrorReportValve.invoke
    (ErrorReportValve.java:99)\n\tat org.apache.catalina.valves.AccessLogValve.invoke
    (AccessLogValve.java:953)\n\tat org.apache.catalina.core.StandardEngineValve.invoke
    (StandardEngineValve.java:118)\n\tat org.apache.catalina.connector.CoyoteAdapter.service
    (CoyoteAdapter.java:408)\n\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    \n\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
    (AbstractProtocol.java:589)\n\tat org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    \n\tat java.util.concurrent.ThreadPoolExecutor$Worker.runTask
    (ThreadPoolExecutor.java:886)
    \n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)\n\tat java.lang.Thread.run(Thread.java:662)\n",
        "code":500}}

如有任何帮助,我们将不胜感激。

最佳答案

错误表明所有定义的拼写检查器都应使用相同的字段。
在您的配置中,您使用不同的字段( spellsuggest )用于不同的检查器。

<str name="field">spell</str><str name="field">suggest</str>

关于java - Solr 所有检查器需要使用相同的分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18775170/

相关文章:

Java 小服务程序 : File download breaks when user navigates away from page

java - jackson-databind 与 spring-core 的问题

java - 如何使用java在多线程中使用log4j?

java - Spring 3 检查是否有 url 的处理程序

java - 使用 Solr 的奇怪行为

tomcat - ubuntu lucid 上的 solr-tomcat 包

linux - 如何修复 drupal 中用于 solCloud 配置的 'You are using an incompatible schema.xml configuration file' 错误

java - 通过反射调用私有(private)静态方法

java - Eclipse - 错误 : Could not find or load main class

java - 实例化 HttpSolrServer 时出现 IllegalAccessError