Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr Did you mean (Spell check component)

I use solr for my apps and i integrated the spellcheck component but i have some problems :

First : When i type a term separated by space they give me the correction for each term

Eg : "wat ters" => "what term" but the true is watters

Second : When i type some phrase with some wrong term. although the other terms are correct they apply the spell for all terms.

Eg : "Difreences in lankuage use conventions" => "Differences in language use conversions".

The true is "Differences in language use conventions"

This is my config in solrconfig.xml :

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
            <str name="queryAnalyzerFieldType">textSpell</str>
            <lst name="spellchecker">
                <str name="name">default</str>
                <str name="field">spell</str>
                <str name="spellcheckIndexDir">spellchecker</str>
            </lst>
</searchComponent>

<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
            <lst name="defaults">
                <str name="spellcheck.onlyMorePopular">true</str>
                <str name="spellcheck.extendedResults">false</str>
                <str name="spellcheck.count">1</str>
            </lst>
            <arr name="last-components">
                <str>spellcheck</str>
            </arr>
</requestHandler>

Schema.xml :

Field type:

<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
            <analyzer type="index">
                <tokenizer class="solr.StandardTokenizerFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
                <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="1" splitOnCaseChange="1"/>
                <filter class="solr.ASCIIFoldingFilterFactory" />
                <filter class="solr.SnowballPorterFilterFactory" language="English"/>
                <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
            </analyzer>
            <analyzer type="query">
                <tokenizer class="solr.StandardTokenizerFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
                <filter class="solr.WordDelimiterFilterFactory" generateWordParts="0" generateNumberParts="0" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0"/>
                <filter class="solr.ASCIIFoldingFilterFactory" />
                <filter class="solr.SnowballPorterFilterFactory" language="English"/>
                <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
            </analyzer>
            <analyzer type="multiterm" >
                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.ASCIIFoldingFilterFactory" />
            </analyzer>
        </fieldType>


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

Fields :

<field name="title" type="text" indexed="true" stored="true" termVectors="true"/>
<field name="spell" type="textSpell" indexed="true" stored="true" multiValued="true"/>

Copy Fields

<copyField source="title" dest="spell"/>

I would appreciate your help

Cheers

like image 762
ZendMind Avatar asked Feb 29 '12 11:02

ZendMind


1 Answers

For your first problem you could use WordBreakSpellChecker

As for your second problem you could set <str name="spellcheck.onlyMorePopular">true</str> to <str name="spellcheck.onlyMorePopular">false</str> and see if this has the expected result.

like image 137
Okke Klein Avatar answered Oct 16 '22 14:10

Okke Klein