Solr Spellcheck查询术语修改

时间:2017-08-28 18:49:25

标签: solr spell-checking

我正在使用Solr进行拼写检查。启用DirectSolrSpellChecker& WordBreakSolrSpellChecker。我有以下问题:

一个。当我在询问“担心”时。 Solr正在将这个术语转换为“worri”并返回相同的结果。如果单词以“y”[“伤害”,“担心”等]结束,则结尾“y”将替换为“i”。

示例查询:

http://localhost:8983/solr/MY_CORE/spell?df=text&spellcheck.q=worry&spellcheck=true&spellcheck.extendedResults=true&spellcheck.onlyMorePopular=true

Solr结果:

<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">5</int>
</lst>
<result name="response" numFound="0" start="0"/>
<lst name="spellcheck">
<lst name="suggestions">
<lst name="worri">
<int name="numFound">9</int>
<int name="startOffset">0</int>
<int name="endOffset">5</int>
<int name="origFreq">5</int>
<arr name="suggestion">
<lst>
<str name="word">wo r ri</str>
<int name="freq">90</int>
</lst>
<lst>
<str name="word">worst</str>
<int name="freq">12</int>
</lst>
<lst>
<str name="word">wo r r i</str>
<int name="freq">5246</int>
</lst>
<lst>
<str name="word">work</str>
<int name="freq">2920</int>
</lst>
<lst>
<str name="word">w o r ri</str>
<int name="freq">530</int>
</lst>
<lst>
<str name="word">worn</str>
<int name="freq">81</int>
</lst>
<lst>
<str name="word">w o r r i</str>
<int name="freq">5246</int>
</lst>
<lst>
<str name="word">wors</str>
<int name="freq">79</int>
</lst>
<lst>
<str name="word">worm</str>
<int name="freq">10</int>
</lst>
</arr>
</lst>
</lst>
<bool name="correctlySpelled">false</bool>
</lst>
</response>

B中。输出上面还有像“w o r r i”这样的单词,我在solr字段中找不到任何这些单词。我也不知道为什么solr会返回字母用空格分隔的单词。

下面是架构文件:

<field name=MY FIELD type="text_en" multiValued="false" indexed="true" stored="true"/>

以下是配置文件:

<!-- a spellchecker built from a field of the main index -->
        <lst name="spellchecker">
            <str name="name">default</str>
            <str name="field"> MY FIELD </str>
            <str name="classname">solr.DirectSolrSpellChecker</str>
            <!-- the spellcheck distance measure used, the default is the internal levenshtein -->
            <str name="distanceMeasure">internal</str>
            <!-- minimum accuracy needed to be considered a valid spellcheck suggestion -->
            <float name="accuracy">0.5</float>
            <!-- the maximum #edits we consider when enumerating terms: can be 1 or 2 -->
            <int name="maxEdits">2</int>
            <!-- the minimum shared prefix when enumerating terms -->
            <int name="minPrefix">1</int>
            <!-- maximum number of inspections per result. -->
            <int name="maxInspections">5</int>
            <!-- minimum length of a query term to be considered for correction -->
            <int name="minQueryLength">4</int>
            <!-- maximum threshold of documents a query term can appear to be considered for correction -->
            <float name="maxQueryFrequency">0.01</float>
            <!-- uncomment this to require suggestions to occur in 1% of the documents
             <float name="thresholdTokenFrequency">.01</float>
             -->
        </lst>

        <!-- a spellchecker that can break or combine words.  See "/spell" handler below for usage -->

         <lst name="spellchecker">
         <str name="name">wordbreak</str>
         <str name="classname">solr.WordBreakSolrSpellChecker</str>
         <str name="field">MY FIELD</str>
         <str name="combineWords">false</str>
         <str name="breakWords">true</str>
         <int name="maxChanges">10</int>
         </lst>

    </searchComponent>


    <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">false</str>
            <str name="spellcheck.collateExtendedResults">false</str>
            <str name="spellcheck.maxCollationTries">10</str>
            <str name="spellcheck.maxCollations">5</str>
        </lst>
        <arr name="last-components">
            <str>spellcheck</str>
        </arr>
    </requestHandler>

如果有人可以帮我解决这个问题,我真的很感激。

提前致谢!

1 个答案:

答案 0 :(得分:0)

&#34;奇怪&#34;你喜欢的建议&#34; wo r r i&#34;。你拥有它们,因为你正在使用WordBreakSolrSpellChecker并且它会打破令牌,试图为你提供一些拼写检查功能,所以如果你删除你就不应该得到这些建议。以下是官方文档中的引用:

  

WordBreakSolrSpellChecker通过组合相邻提供建议   查询术语和/或将术语分成多个单词。它是一个   SpellCheckComponent增强,利用Lucene&#39; s   WordBreakSpellChecker。它可以检测由此产生的拼写错误   错误的空格而不使用基于单词的词典和   为分词错误提供整理支持,包括案例   用户混合使用单字拼写错误和分词   同一查询中的错误。它还提供了分片支持。

所以,基本上,在你的例子中 - 你从Solr索引得到了正常的建议,如:worst, work, worm, worn, wors。所有其他只是WordBreakSolrSpellChecker的结果,你永远不会在索引中找到它们。