【发布时间】:2013-05-14 15:01:58
【问题描述】:
我们正在尝试使用 Solr 来更正搜索框中某些测试的拼写。我们发现它是这样工作的:
http://localhost:8080/solr/collection1/spell?q=badspelled&spellcheck=true
它会返回一组建议的术语。但我们需要的不是建议列表,而是 Solr 直接使用第一个建议进行搜索。这可能吗?
【问题讨论】:
标签: solr
我们正在尝试使用 Solr 来更正搜索框中某些测试的拼写。我们发现它是这样工作的:
http://localhost:8080/solr/collection1/spell?q=badspelled&spellcheck=true
它会返回一组建议的术语。但我们需要的不是建议列表,而是 Solr 直接使用第一个建议进行搜索。这可能吗?
【问题讨论】:
标签: solr
您需要将“spellcheck.collate=true”参数添加到您的第一个搜索查询中,然后在响应中使用“collation”值来触发具有该值的第二个查询。
插件页面示例:
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
【讨论】: