字母排序不适用于使用haystack的弹性搜索

时间:2014-05-12 10:19:36

标签: django search elasticsearch django-haystack

我正在使用haystack进行弹性搜索。我的问题是我无法按字母顺序排序结果。请注意,内容是希腊语。以下是我的索引。

class ProfileIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.EdgeNgramField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    sorted_title = indexes.CharField(model_attr='title', indexed=False, stored=True)

我已经添加了sorted_title专门用于排序。

这里是索引设置:

    ELASTICSEARCH_INDEX_SETTINGS = {
    'settings': {
        "analysis": {
            "analyzer": {
                "ngram_analyzer": {
                    "type": "custom",
                    "tokenizer": "haystack_ngram_tokenizer",
                    "filter": [
                        "lowercase",
                        "greek_lowercase",
                        "greek_stem",
                        "english_stem",
                        "my_stop",
                        "haystack_ngram"
                    ]
                },
                "edgengram_analyzer": {
                    "type": "custom",
                    "tokenizer": "standard",
                    "filter": [
                        "lowercase",
                        "greek_lowercase",
                        "greek_stem",
                        "english_stem",
                        "my_stop",
                        "haystack_edgengram"
                    ]
                },
                "myanalyzer": {
                    "type": "custom",
                    "tokenizer": "standard",
                    "filter": [
                        "lowercase",
                        "greek_lowercase",
                        "greek_stem",
                        "english_stem",
                        "my_stop",
                        "my_edgengram",
                    ]
                },
            },
            "tokenizer": {
                "haystack_ngram_tokenizer": {
                    "type": "nGram",
                    "min_gram": 1,
                    "max_gram": 12,
                },
                "haystack_edgengram_tokenizer": {
                    "type": "edgeNGram",
                    "min_gram": 1,
                    "max_gram": 12,
                    "side": "front"
                }
            },
            "filter": {
                "haystack_ngram": {
                    "type": "nGram",
                    "min_gram": 1,
                    "max_gram": 12
                },
                "haystack_edgengram": {
                    "type": "edgeNGram",
                    "min_gram": 1,
                    "max_gram": 12
                },
                "my_edgengram": {
                    "type": "edgeNGram",
                    "min_gram": 1,
                    "max_gram": 10
                },
                "my_ngram": {
                    "type": "nGram",
                    "min_gram": 1,
                    "max_gram": 10
                },
                "greek_lowercase": {
                    "type": "lowercase",
                    "language": "greek"
                },
                "greek_stem": {
                    "type": "stemmer",
                    "name": "greek"
                },
                "english_stem": {
                    "type": "stemmer",
                    "name": "english"
                },
                "my_stop": {
                    "type": "stop",
                    "stopwords": ["_greek_", "_english_"]
                }
            }
        }
    }
}

任何帮助都将不胜感激。

感谢。

0 个答案:

没有答案