如何使用Hibernate Lucene Search进行不区分大小写的挪威字符(Æ,Ø和Å)排序?

如何使用Hibernate Lucene Search进行不区分大小写的挪威字符(Æ,Ø和Å)排序?,第1张

如何使用Hibernate Lucene Search进行不区分大小写挪威字符(Æ,Ø和Å)排序?

您可以

org.apache.lucene.collation.CollationKeyFilter
在Hibernate
Search版本4.3.0.Final中使用类。创建自己的归类过滤器工厂:

import org.apache.lucene.analysis.TokenStream;import org.apache.lucene.collation.CollationKeyFilter;import org.apache.solr.analysis.baseTokenFilterFactory;import java.text.Collator;import java.util.Locale;public final class NorwegianCollationFactory extends baseTokenFilterFactory {    @Override    public TokenStream create(TokenStream input) {        Collator norwegianCollator = Collator.getInstance(new Locale("no", "NO"));        return new CollationKeyFilter(input, norwegianCollator);    }}

并在AnalyzerDef中使用以下整理工厂

@AnalyzerDef(name = "myOwnAnalyzer",tokenizer = @TokenizerDef(factory = KeywordTokenizerFactory.class),filters = {    @TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),    @TokenFilterDef(factory = LowerCaseFilterFactory.class),    @TokenFilterDef(factory = PatternReplaceFilterFactory.class, params = {        @Parameter(name = "pattern", value = "('-&\.,\(\))"),        @Parameter(name = "replacement", value = " "),        @Parameter(name = "replace", value = "all")    }),    @TokenFilterDef(factory = PatternReplaceFilterFactory.class, params = {        @Parameter(name = "pattern", value = "([^0-9\p{L} ])"),        @Parameter(name = "replacement", value = ""),        @Parameter(name = "replace", value = "all")    }),    @TokenFilterDef(factory = TrimFilterFactory.class),    @TokenFilterDef(factory = NorwegianCollationFactory .class)})public class KikaPaya implements Serializable {


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5442622.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存