如何在Solr中使用配置API添加具有多个字典的suggester组件?
根据,使用config API添加带有1个字典的suggester组件是通过以下请求完成的:如何在Solr中使用配置API添加具有多个字典的suggester组件?,solr,Solr,根据,使用config API添加带有1个字典的suggester组件是通过以下请求完成的: { "add-searchcomponent": { "name": "suggest", "class": "solr.SuggestComponent", "suggester": { "na
{
"add-searchcomponent": {
"name": "suggest",
"class": "solr.SuggestComponent",
"suggester": {
"name": "suggest",
"lookupImpl": "AnalyzingInfixLookupFactory",
"dictionaryImpl": "DocumentDictionaryFactory",
"field": "_suggestField_",
"suggestAnalyzerFieldType": "suggest_text"
}
}
}
但是,指南中没有记录对多个词典执行相同操作
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">cat</str>
<str name="weightField">price</str>
<str name="suggestAnalyzerFieldType">string</str>
</lst>
<lst name="suggester">
<str name="name">altSuggester</str>
<str name="dictionaryImpl">DocumentExpressionDictionaryFactory</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="field">product_name</str>
<str name="weightExpression">((price * 2) + ln(popularity))</str>
<str name="sortField">weight</str>
<str name="sortField">price</str>
<str name="storeDir">suggest_fuzzy_doc_expr_dict</str>
<str name="suggestAnalyzerFieldType">text_en</str>
</lst>
</searchComponent>
事实证明,Solr config API可以接受具有重复键的JSON。我们可以将上面的suggester XML配置转换为下面的配置API请求
正确的方法是将suggester
设置为数组
{
"add-searchcomponent": {
"name": "suggest",
"class": "solr.SuggestComponent",
"suggester": [
{
"name": "mySuggester",
"lookupImpl": "FuzzyLookupFactory",
"dictionaryImpl": "DocumentDictionaryFactory",
"field": "cat",
"weightField": "price",
"suggestAnalyzerFieldType": "string"
},
{
"name": "altSuggester",
"lookupImpl": "FuzzyLookupFactory",
"dictionaryImpl": "DocumentDictionaryFactory",
"field": "product_name",
"weightExpression": "((price * 2)) + ln(popularity)",
"sortField": "price",
"storeDir": "suggest_fuzzy_doc_expr_dict",
"suggestAnalyzerFieldType": "text_en"
}
]
}
}
当您查询ConfigAPI时,您将看到请求和保存的配置是相同的
感谢@MatsLindh为我们提供了解决这个问题的方法 您是否检查了在XML文件中初始配置建议程序时ConfigAPI返回的内容?嗨@MatsLindh,我已经更新了这个问题以包含建议配置。顺便说一句,我还使用了配置API来配置我的建议组件。我的想法是,如果您最初将其配置为XML,然后使用配置API检索该配置,它可以为您提供有关如何(如果)支持它的提示-也许您可以给
建议
或建议
键的列表。@MatsLindh,我试着做一个简单但违反直觉的请求,结果成功了。事实证明,Solr可以接受具有重复密钥的属性的JSON(即suggester
)。我会把它贴出来作为将来的参考答案。无论如何,非常感谢你的帮助!
{
"add-searchcomponent": {
"name": "suggest",
"class": "solr.SuggestComponent",
"suggester": [
{
"name": "mySuggester",
"lookupImpl": "FuzzyLookupFactory",
"dictionaryImpl": "DocumentDictionaryFactory",
"field": "cat",
"weightField": "price",
"suggestAnalyzerFieldType": "string"
},
{
"name": "altSuggester",
"lookupImpl": "FuzzyLookupFactory",
"dictionaryImpl": "DocumentDictionaryFactory",
"field": "product_name",
"weightExpression": "((price * 2)) + ln(popularity)",
"sortField": "price",
"storeDir": "suggest_fuzzy_doc_expr_dict",
"suggestAnalyzerFieldType": "text_en"
}
]
}
}