【问题标题】:Make Solr automatically search by first suggestion in spell correction使 Solr 在拼写更正中通过第一个建议自动搜索
【发布时间】:2013-05-14 15:01:58
【问题描述】:

我们正在尝试使用 Solr 来更正搜索框中某些测试的拼写。我们发现它是这样工作的:

http://localhost:8080/solr/collection1/spell?q=badspelled&spellcheck=true

它会返回一组建议的术语。但我们需要的不是建议列表,而是 Solr 直接使用第一个建议进行搜索。这可能吗?

【问题讨论】:

    标签: solr


    【解决方案1】:

    您需要将“spellcheck.collat​​e=true”参数添加到您的第一个搜索查询中,然后在响应中使用“collat​​ion”值来触发具有该值的第二个查询。

    插件页面示例:

    http://localhost:8983/solr/spell?q=price:[80 TO 100] delll ultrashar&spellcheck=true&spellcheck.extendedResults=true&spellcheck.collate=true
    

    这会返回建议:

    <lst name="spellcheck">
      <lst name="suggestions">
        <lst name="delll">
          <int name="numFound">1</int>
          <int name="startOffset">18</int>
          <int name="endOffset">23</int>
          <int name="origFreq">0</int>
          <arr name="suggestion">
            <lst>
              <str name="word">dell</str>
              <int name="freq">2</int>
            </lst>
          </arr>
        </lst>
        <lst name="ultrashar">
          <int name="numFound">1</int>
          <int name="startOffset">24</int>
          <int name="endOffset">33</int>
          <int name="origFreq">0</int>
          <arr name="suggestion">
            <lst>
              <str name="word">ultrasharp</str>
              <int name="freq">2</int>
            </lst>
          </arr>
        </lst>
        <bool name="correctlySpelled">false</bool>
        <str name="collation">price:[80 TO 100] dell ultrasharp</str>
      </lst>
    </lst>
    

    然后使用建议的查询触发另一个查询:

    http://localhost:8983/solr/spell?q=price:[80 TO 100] dell ultrasharp&spellcheck=true&spellcheck.extendedResults=true&spellcheck.collate=true
    

    SpellCheck collate

    【讨论】:

    • 是否可以让 Solr 做到这一点?发送第二个查询看起来有点矫枉过正。当然可以编写一个至少在同一个节点上触发第二个查询的 HTTPHandler,但是是否有可能在 Solr 本身中获取第二个查询?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 2014-12-01
    相关资源
    最近更新 更多