每个领域的不同分析仪 [英] Different analyzers for each field

查看:15
本文介绍了每个领域的不同分析仪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为使用 Lucene 编制索引的文档中的每个字段启用不同的分析器?示例:

How can I enable different analyzers for each field in a document I'm indexing with Lucene? Example:

        RAMDirectory dir = new RAMDirectory();
        IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED);
        Document doc = new Document();
        Field field1 = new Field("field1", someText1, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
        Field field2 = new Field("field2", someText2, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
        doc.Add(field1);
        doc.Add(field2);
        iw.AddDocument(doc);
        iw.Commit();

分析器是 IndexWriter 的参数,但我想对 field1 使用 StandardAnalyzer,对 field2 使用 SimpleAnalyzer,我该怎么做?当然,搜索时也是如此.必须为每个字段应用正确的分析器.

The analyzer is an argument to the IndexWriter, but I want to use StandardAnalyzer for field1 and SimpleAnalyzer for field2, how can I do that? The same applies when searching, of course. The correct analyzer must be applied for each field.

推荐答案

PerFieldAnalyzerWrapper 是您正在寻找的.在 Lucene.net 中相当于 这里.

PerFieldAnalyzerWrapper is what you are looking for. The equivalent of this in Lucene.net is here.

这篇关于每个领域的不同分析仪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆