Different analyzers for each field

Posted by user72185 on Stack Overflow See other posts from Stack Overflow or by user72185
Published on 2010-05-16T09:00:01Z Indexed on 2010/05/16 9:10 UTC
Read the original article Hit count: 226

Filed under:
|

Hi,

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();

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.

© Stack Overflow or respective owner

Related posts about lucene

Related posts about lucene.net