ElasticSearch - define custom letter order for sorting

拟墨画扇 提交于 2019-12-06 12:35:29

I've never used it, but there is a plugin that could fit your needs: the ICU collation plugin.

You will have to use the icu_collation token filter, which will turns the tokens into collation keys. For that reason you will need to use a separate @Field (e.g. myField_sort) in Hibernate Search.

You can assign a specific analyzer to your field with @Field(name = "myField_sort", analyzer = @Analyzer(definition = "myCollationAnalyzer")), and define this analyzer (type, parameters) with something like that on one of your entities:

@Entity
@Indexed
@AnalyzerDef(
    name = "myCollationAnalyzer",
    filters = {
        @TokenFilterDef(
            name = "polish_collation",
            factory = ElasticsearchTokenFilterFactory.class,
            params = {
                @Parameter(name = "type", value = "'icu_collation'"),
                @Parameter(name = "language", value = "'pl'")
            }
        )
    }
)
public class MyEntity {

See the documentation for more information: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#_custom_analyzers

It's admittedly a bit clumsy right now, but analyzer configuration will get a bit cleaner in the next Hibernate Search version with normalizers and analyzer definition providers.

Note: as usual, your field will need to be declared as sortable (@SortableField(forField = "myField_sort")).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!