如何在 Solr 中使用 Config API 添加具有多个词典的建议组件?

How to add suggester component with multiple dictionaries using Config API in Solr?

根据 Solr guide,使用配置 API 添加带有 1 个字典的建议组件是使用以下请求完成的:

{
    "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>

如何将上述 XML 配置转换为配置 API 请求?

编辑:我已经用 1 个字典配置了建议组件,这是建议配置的样子(通过配置 api)

"suggest": {
    "name": "suggest",
    "class": "solr.SuggestComponent",
    "suggester": {
        "name": "tags",
        "lookupImpl": "AnalyzingInfixLookupFactory",
        "dictionaryImpl": "DocumentDictionaryFactory",
        "field": "_tagSuggest_",
        "weightField": "price",
        "suggestAnalyzerFieldType": "suggest_text"
    }
}

事实证明,Solr 配置 API 可以接受具有重复键的 JSON。我们可以将上面的 suggester XML 配置转换为下面的配置 API request.

正确的做法是将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"
            }
        ]
    }
}

当您查询配置API时,您会看到请求和保存的配置相同。

感谢@MatsLindh 建议解决这个问题的方法!