Solr仅为Suggester Component返回一个排序规则

Adr*_*ian 6 solr autocomplete collation autosuggest

我使用solr 3.6并且我想使用来自建议器的排序作为多项搜索的自动完成解决方案.不幸的是,即使对每个单个术语存在大量建议,"建议器"也只返回一个多项搜索的排序规则.根据我的测试搜索和底层索引数据,我确信必须存在更多的排序规则.

我的Suggester配置有问题吗?

    <!--configuration -->
<searchComponent class="solr.SpellCheckComponent" name="suggest">
<lst name="spellchecker">
  <str name="name">suggest</str>
  <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
  <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.WFSTLookupFactory</str>
  <str name="field">text</str>  <!-- the indexed field to derive suggestions from -->
  <!--<float name="threshold">0.0005</float> disabled for test-->
  <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">200</str>
  <str name="spellcheck.collate">true</str>
  <str name="spellcheck.maxCollations">10</str>
</lst>
<arr name="components">
  <str>suggest</str>
</arr>
</requestHandler> 
Run Code Online (Sandbox Code Playgroud)

q = bio + ber的示例响应:

<response>
<lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">4</int>
</lst>
<lst name="spellcheck">
    <lst name="suggestions">
        <lst name="bio">
            <int name="numFound">27</int>
            <int name="startOffset">0</int>
            <int name="endOffset">3</int>
            <arr name="suggestion">
                <str>bio</str>
                <str>bio-estetica</str>
                <str>bio-kosmetik</str>
                                    ...
            </arr>
        </lst>
        <lst name="ber">
            <int name="numFound">81</int>
            <int name="startOffset">4</int>
            <int name="endOffset">7</int>
            <arr name="suggestion">
                <str>beratung</str>
                <str>bern</str>
                ...
            </arr>
        </lst>
        <str name="collation">bio beratung</str>
    </lst>
</lst>
</response>
Run Code Online (Sandbox Code Playgroud)

nla*_*son 14

我和你有同样的问题,我设法解决了.事实证明,为了让多个排序规则正常运行,您需要了解一些事项.

首先,您必须在您的"建议"列表QueryComponent下指定一个.否则您不知道如何查询索引,因此无法确定每个更正的查询有多少次点击,因此您只能得到一个.如果您已添加到查询中,您会看到0为0,这表明Solr没有费心去检查针对索引的更正查询.componentsrequestHandlersolrconfig.xmlrequestHandlerspellcheck.collateExtendedResults=truehits

他们暗示了一个有点不透明的错误消息:

INFO: Could not find an instance of QueryComponent. Disabling collation verification against the index.

添加它的最简单方法是使用默认值QueryComponent,称为"查询".因此,在上面发布的XML中,您将"组件"部分更改为:

<arr name="components">
  <str>suggest</str>
  <str>query</str>
</arr>
Run Code Online (Sandbox Code Playgroud)

其次,您需要设置spellcheck.maxCollations为大于1(duh),并且不太直观,您需要设置spellcheck.maxCollationTries为一些大数字(例如1000).如果将其中任何一个设置为默认值(均为0),则Solr将仅为您提供一个排序规则.此外,您需要设置spellcheck.count为大于1.

第三,您需要修改查询以包含要搜索的字段,并且术语必须用引号括起以确保正确的排序规则.所以在你的查询的情况下:

q=bio+ber

这应该是:

q=text:"bio+ber"

显然,在您的情况下,"text"是默认字段,因此您不需要它.但就我而言,我使用的是非默认字段,因此我必须指定它.否则,Solr会根据"文本"字段计算命中数,并且所有结果都会有0次命中,因此排名将无用.

所以在我的例子中,查询看起来像这样:

q=my_field:"brain+c"
&spellcheck.count=5
&spellcheck.maxCollations=10
&spellcheck.maxCollationTries=1000
&spellcheck.collateExtendedResults=true
Run Code Online (Sandbox Code Playgroud)

我的回答看起来像这样:

<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">4</int>
  </lst>
  <lst name="spellcheck">
    <lst name="suggestions">
      <lst name="brain">
        <int name="numFound">1</int>
        <int name="startOffset">15</int>
        <int name="endOffset">20</int>
        <arr name="suggestion">
          <str>brain</str>
        </arr>
      </lst>
      <lst name="c">
        <int name="numFound">4</int>
        <int name="startOffset">21</int>
        <int name="endOffset">23</int>
        <arr name="suggestion">
          <str>cancer</str>
          <str>cambrian</str>
          <str>contusion</str>
          <str>cells</str>
        </arr>
      </lst>
      <lst name="collation">
        <str name="collationQuery">my_field:"brain cancer"</str>
        <int name="hits">2</int>
        <lst name="misspellingsAndCorrections">
          <str name="brain">brain</str>
          <str name="c">cancer</str>
        </lst>
      </lst>
      <lst name="collation">
        <str name="collationQuery">my_field:"brain contusion"</str>
        <int name="hits">1</int>
        <lst name="misspellingsAndCorrections">
          <str name="brain">brain</str>
          <str name="c">contusion</str>
        </lst>
      </lst>
      <lst name="collation">
        <str name="collationQuery">my_field:"brain cells"</str>
        <int name="hits">1</int>
        <lst name="misspellingsAndCorrections">
          <str name="brain">brain</str>
          <str name="c">cells</str>
        </lst>
      </lst>
    </lst>
  </lst>
  <result name="response" numFound="0" start="0"/>
</response>
Run Code Online (Sandbox Code Playgroud)

成功!