首页 > 解决方案 > Wagtail:Elasticsearch 不会在短字段上提升匹配

问题描述

我们正在搜索具有街道、街道编号和城市的模型。streetnumber 上的完全匹配应该会将该结果放在首位,但我们无法让它发挥作用,有什么想法吗?

后端设置:

"default": {
        "BACKEND": "wagtail.search.backends.elasticsearch7",
        "URLS": [host.strip() for host in es_host.split(",")],
        "INDEX": APP_ENV_NAME,
        "TIMEOUT": 5,
        "OPTIONS": {},
        "INDEX_SETTINGS": {
            "settings": {
                "analysis": {
                    # Replace default 'asciifolding' filter from Wagtail defaults.
                    # It converts non-ASCII characters (e.g. å -> a), breaking
                    # searches in Swedish. Adding preserve_original allows searching
                    # for both the original and the ASCII version.
                    "analyzer": {
                        "ngram_analyzer": {
                            "filter": ["asciifolding", "ngram"]
                        },
                        "edgengram_analyzer": {
                            "filter": ["asciifolding", "edgengram"]
                        },
                    },
                    "filter": {
                        "asciifolding": {
                            "type": "asciifolding",
                            "preserve_original": True,
                        }
                    },
                }
            }
        },
    }
}

模型设置:

search_fields = [
    index.SearchField("street", partial_match=True),
    index.SearchField("city", partial_match=True),
    index.SearchField("street_nr"),
    index.FilterField("active"),
]

标签: pythonelasticsearchwagtail

解决方案


推荐阅读