我是Solr的新手,正在尝试通过Config API添加Suggest Search组件。
我的Solr 9.0.0设置如下:
-
bin/solr start -e cloud
,带_default配置 -
使用
bin/post -c collection_name file_path/file.csv
对csv进行索引 -
将带有POST请求的搜索组件添加到
http://localhost:8983/api/collections/collection_name/config
:
{
"add-searchcomponent": {
"name": "suggest",
"class": "solr.SuggestComponent",
"lookupImpl": "FuzzyLookupFactory",
"dictionaryImpl": "DocumentDictionaryFactory",
"field": "name",
"suggestAnalyzerFieldType": "string",
"buildOnStartup": false
}
}
- 将带有POST请求的请求处理程序添加到
http://localhost:8983/api/collections/collection_name/config
:
{
"add-requesthandler": {
"name": "/suggest",
"startup": "lazy",
"class": "solr.SearchHandler",
"defaults": {
"suggest": true,
"suggest.count": 10
},
"components": ["suggest"]
}
}
这很好用,我的configoverlay.json如下所示:
{
"props":{"updateHandler":{"autoSoftCommit":{"maxTime":3000}}},
"searchComponent":{"suggest":{
"name":"suggest",
"class":"solr.SuggestComponent",
"lookupImpl":"FuzzyLookupFactory",
"dictionaryImpl":"DocumentDictionaryFactory",
"field":"name",
"suggestAnalyzerFieldType":"string",
"buildOnStartup":false}},
"requestHandler":{"/suggest":{
"name":"/suggest",
"startup":"lazy",
"class":"solr.SearchHandler",
"defaults":{
"suggest":true,
"suggest.count":10},
"components":["suggest"]}}}
但如果我发送请求http://localhost:8983/solr/collection_name/suggest?suggest.dictionary=suggest&q=J&suggest.build=true
,我会收到以下错误:
{
"responseHeader": {
"zkConnected": true,
"status": 400,
"QTime": 3
},
"error": {
"metadata": [
"error-class",
"org.apache.solr.common.SolrException",
"root-error-class",
"org.apache.solr.common.SolrException"
],
"msg": "No suggester named suggest was configured",
"code": 400
}
}
我可以想象这与搜索组件的命名有关,因为文档中定义了两个不同的名称。有一个";searchComponent name";和一个";name";参数,但我现在不知道如何操作";searchComponent name";。
我发现这篇和这篇文章都有类似的错误,但这两篇文章都是关于没有配置suggest.dictionary的,这在我的情况下不是这样。
对于我做错的事情,我们将不胜感激。
一个SuggestComponent可以使用多个字典,因此您必须在列表中定义它们,并为每个字典显式指定一个name
。
还要注意,buildOnStartup
需要一个字符串。
{
"add-searchcomponent": {
"name": "suggest",
"class": "solr.SuggestComponent",
"suggester": [{
"name": "fuzzy",
"lookupImpl": "FuzzyLookupFactory",
"dictionaryImpl": "DocumentDictionaryFactory",
"field": "name",
"suggestAnalyzerFieldType": "string",
"buildOnStartup": "false"
}]
}
}
您可以使用.../suggest?suggest.dictionary=fuzzy&q=J&suggest.build=true
查询