0

All, I am trying to apply the spell check in the Solr 5.3.1.

Currently Solr 5.3.1 already includes the SpellCheckComponent. which looks like below .

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
        <str name="queryAnalyzerFieldType">text_general</str>
        <lst name="spellchecker">
            <str name="name">default</str>
            <str name="field">text</str>
            <str name="classname">solr.DirectSolrSpellChecker</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>
        </lst>
        <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>

But When I tried to consume this function. like this.

http://10.2.21.38:7574/solr/gettingstarted_shard1_replica2/spell?q=%E7%94%B2&wt=json&indent=true

I got response with exception said

All checkers need to use the same Analyzer

I also tried to search some solution from the internet. and found some solutions like below .

Solr 4.0 How can I change the spellchecker analysers so they are all the same?

Solr spellcheck: cannot show result, always receiving same error

So I tried to follow the answers to change these fields to the same one.

<str name="field">text</str>
<str name="field">name</str>

to the same field

like this .

...
<str name="field">EntryCNName</str>

....
<str name="field">EntryCNName</str>

which is defined in the schema.

<field name="EntryCNName" type="text_ik" indexed="true" stored="true"/>

the field type definition is

<fieldType name="text_ik" class="solr.TextField">
    <analyzer type="index" isMaxWordLength="false" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
    <analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>

But unfortunately still got the same error. Could someone please help to figure out what does it mean for this error ? How to fix it ?

Thanks.

Upated

I make something progress.

I found the <str name="field">xx</str> defined in the searchComponent should defined in the schema. and in the requestHandler .the xxx of the <str name="spellcheck.dictionary">xxx</str> should be from the spellchecker name. for example in my case they are default and wordbreak.

So I change my configuration like below.

Schema.xml

    <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
    <field name="_version_" type="long" indexed="true" stored="true"/>
    <field name="_root_" type="string" indexed="true" stored="false"/>
    <!--<field name="Name" type="string" indexed="true" stored="true"/>-->
    <field name="EntityID" type="string" indexed="false" stored="true"/>
    <field name="EntryCNName" type="text_ik" indexed="true" stored="true"/>
    <field name="EntryEnName" type="string" indexed="true" stored="true"/>
    <field name="EntryType" type="string" indexed="false" stored="true"/>
    <field name="_text_" type="text_general" indexed="true" stored="true" multiValued="true"/>
    <field name="spell" type="textSpell" indexed="true" stored="true" multiValued="true" />
    <!--<field name="content" type="text_general" indexed="true" stored="true" required="true" />-->
    <copyField source="*" dest="_text_"/>
    <copyField source="EntryEnName" dest="spell" />



<fieldType name="textSpell" class="solr.TextField" positionIncrementGap="100" omitNorms="true">
        <analyzer type="index">
            <tokenizer class="solr.StandardTokenizerFactory" />
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
            <filter class="solr.LowerCaseFilterFactory" />
            <filter class="solr.StandardFilterFactory" />
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.StandardTokenizerFactory" />
            <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
            <filter class="solr.LowerCaseFilterFactory" />
            <filter class="solr.StandardFilterFactory" />
        </analyzer>
    </fieldType>

SolrConfig.xml

<lst name="spellchecker">
            <str name="name">default</str>
            <str name="classname">solr.IndexBasedSpellChecker</str>
            <str name="field">spell</str>
            <str name="spellcheckIndexDir">/path/to/my/spell/index</str>
            <str name="accuracy">0.7</str>
            <float name="thresholdTokenFrequency">.0001</float>

        </lst>

        <lst name="spellchecker">
            <str name="name">wordbreak</str>
            <str name="classname">solr.WordBreakSolrSpellChecker</str>
            <str name="field">spell</str>
            <str name="spellcheckIndexDir">/path/to/my/spell/index</str>
            <str name="combineWords">true</str>
            <str name="breakWords">true</str>
            <int name="maxChanges">10</int>
        </lst>



<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
        <lst name="defaults">

            <str name="spellcheck.dictionary">default</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>

Now the error is gone . But when I call the url like

http://10.2.21.38:7574/solr/gettingstarted_shard1_replica2/spell?q=lu&spellcheck=true&spellcheck.collate=true&spellcheck.build=true

I got empty suggestions.

<lst name="spellcheck">
<lst name="suggestions"/>
<bool name="correctlySpelled">false</bool>
<lst name="collations"/>
</lst>

And Actually . I can search many results with the keywords lung. why solr doesn't suggest the Lung when I tried the lu? Anything I missed .Thanks.

enter image description here

Community
  • 1
  • 1
Joe.wang
  • 11,537
  • 25
  • 103
  • 180
  • were you able to fix it. I have tried same config as yours but still same error. – Suneel Kumar Jun 25 '16 at 11:25
  • 1
    Try to check you configuration by following http://stackoverflow.com/questions/6653186/solr-suggester-not-returning-any-results. Good luck. – Joe.wang Jun 26 '16 at 12:33

0 Answers0