我想实施一个Solr建议器(http://wiki.apache.org/solr/Suggester),按文档提升因子对建议进行排名。
据我了解文档,以下配置应该有效。但结果仍按字母顺序排列。
我缺少什么想法?我使用Solr 4.0.0。
谢谢, 米尔科
solrconfig.xml中:
...
<requestHandler name="/suggest" class="solr.SearchHandler">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.count">7</str>
<str name="spellcheck.onlyMorePopular">true</str>
</lst>
<arr name="last-components">
<str>suggest</str>
</arr>
</requestHandler>
<searchComponent class="solr.SpellCheckComponent" name="suggest">
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">suggesttext</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.fst.WFSTLookupFactory</str>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
...
Schema.xml的:
...
<field name="suggesttext" type="text" indexed="true" stored="true" multiValued="true"/>
...
<fieldType name="text" class="solr.TextField" omitNorms="false"/>
...
我添加了三个带有文档提升的文档:
{
"add": {
"commitWithin": 5000,
"overwrite": true,
"boost": 3.0,
"doc": {
"id": "1",
"suggesttext": "text bb"
}
},
"add": {
"commitWithin": 5000,
"overwrite": true,
"boost": 2.0,
"doc": {
"id": "2",
"suggesttext": "text cc"
}
},
"add": {
"commitWithin": 5000,
"overwrite": true,
"boost": 1.0,
"doc": {
"id": "3",
"suggesttext": "text aa"
}
}
}
查询建议处理程序(使用spellcheck.q = te)给出以下响应:
{
"responseHeader":{
"status":0,
"QTime":6},
"command":"build",
"response":{"numFound":3,"start":0,"docs":[
{
"id":"1",
"suggesttext":["text bb"]},
{
"id":"2",
"suggesttext":["text cc"]},
{
"id":"3",
"suggesttext":["text aa"]}]
},
"spellcheck":{
"suggestions":[
"te",{
"numFound":3,
"startOffset":0,
"endOffset":2,
"suggestion":["text aa",
"text bb",
"text cc"]}]}}
搜索结果按预期按提升排名。但是,建议不按升级排名(而是按字母顺序排列)。我也尝试了相同结果的TSTLookup和FSTLookup查找实现。