【问题标题】:How to add suggester component with multiple dictionaries using Config API in Solr?如何在 Solr 中使用 Config API 添加具有多个字典的建议器组件?
【发布时间】:2020-10-19 19:50:37
【问题描述】:

根据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 个字典配置了建议器组件,这是建议配置的样子(通过 config api)

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

【问题讨论】:

  • 您是否检查过最初在 XML 文件中配置建议器时 Config API 返回的内容?
  • 嗨@MatsLindh,我已经更新了问题以包含建议配置。顺便说一句,我还使用 config API 来配置我的建议组件。
  • 我的想法是,如果您最初将其配置为 XML,然后使用 config api 检索 that 配置,它可以为您提供有关如何(如果)它的提示被支持——也许你可以给suggestsuggester键提供一个列表?
  • @MatsLindh,我尝试做一个简单但违反直觉的请求,它奏效了。事实证明,Solr 可以接受带有重复键属性的 JSON(即suggester)。我会将其发布为将来参考的答案。无论如何,非常感谢您的帮助!

标签: solr


【解决方案1】:

事实证明,Solr 配置 API 可以接受带有重复键的 JSON。我们可以将上面的建议 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"
            }
        ]
    }
}

查询config API时,会看到请求和保存的配置是一样的。

感谢@MatsLindh 提出解决此问题的方法!

【讨论】:

    猜你喜欢
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-18
    相关资源
    最近更新 更多