Different analyzers for each field

后端 未结 3 1115
失恋的感觉
失恋的感觉 2021-02-05 05:29

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

        RAMDirectory dir = new RAMDirectory();
        Ind         


        
相关标签:
3条回答
  • 2021-02-05 06:03

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

    0 讨论(0)
  • 2021-02-05 06:10
    Map<String, Analyzer> analyzerMap = new HashMap<String, Analyzer>();
    analyzerMap.put(fieldone, new IKAnalyzer4PinYin(false, IKAnalyzer4PinYin.PINYIN));
    analyzerMap.put(fieldtwo, new IKAnalyzer4PinYin(false, KAnalyzer4PinYin.PINYIN_SHOUZIMU));
    PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper(new IKAnalyzer4PinYin(false), analyzerMap);
    
    IndexWriterConfig iwConfig = new IndexWriterConfig(Version.LUCENE_40 , wrapper);
    
    0 讨论(0)
  • 2021-02-05 06:14

    Necromancing.
    For C#:

    Lucene.Net.Util.LuceneVersion version = Lucene.Net.Util.LuceneVersion.LUCENE_48;
    
    Dictionary<string, Lucene.Net.Analysis.Analyzer> fieldAnalyzers = 
        new Dictionary<string, Lucene.Net.Analysis.Analyzer>(System.StringComparer.OrdinalIgnoreCase);
    
    fieldAnalyzers["YourFieldName"] = new Lucene.Net.Analysis.Core.KeywordAnalyzer();
    
    Lucene.Net.Analysis.Miscellaneous.PerFieldAnalyzerWrapper wrapper = 
        new Lucene.Net.Analysis.Miscellaneous.PerFieldAnalyzerWrapper(
            new Lucene.Net.Analysis.Core.KeywordAnalyzer(), fieldAnalyzers);
    
    Lucene.Net.Index.IndexWriterConfig writerConfig = new Lucene.Net.Index.IndexWriterConfig(version, wrapper);
    
    0 讨论(0)
提交回复
热议问题