开发者

ASCIIFoldingFilter usage example on Lucene.NET

开发者 https://www.devze.com 2023-02-16 03:43 出处:网络
I am trying to implement my search on Lucene.NET and my needs are: search and find the result directly

I am trying to implement my search on Lucene.NET and my needs are:

  • search and find the result directly
  • if there is no result, search again with Accent Insensitive

I did it on 开发者_如何学PythonSQL Server but I want to move it to Lucene.NET. I made a research and first I found ISOLatinFilter and then ASCIIFoldingFilter in Lucene. But I couldn't find a simple example how to use it (Even in Lucene in Action book)

Can you please give me a small sample code to achieve accent insensitive search? Do I need to change anything else on Indexing? As I need accent sensitive also, I cannot create an Accent insensitive index only.

Thanks


Use this class as your Analyzer on index and search, Works for me.

    public class CustomAnalyzer : StandardAnalyzer
    {
        Lucene.Net.Util.Version matchVersion;

        public CustomAnalyzer(Lucene.Net.Util.Version p_matchVersion)
            : base(p_matchVersion)
        {
            matchVersion = p_matchVersion;
        }

        public override TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
        {
            TokenStream result = new StandardTokenizer(matchVersion, reader);
            result = new StandardFilter(result);
            result = new ASCIIFoldingFilter(result);
            return result;
        }

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消