using Lucene.Net.Index; using Lucene.Net.Documents; // create a new index writer IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED); // create a new SegString instance SegString segString = new SegString(","); // create a new document and add fields Document doc = new Document(); doc.Add(new Field("id", "1", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("message", "This is a sample message, with commas to be segmented.", Field.Store.YES, Field.Index.ANALYZED)); // split the message field into segments and add them to the document foreach (string segment in segString.Segment(doc.Get("message"))) { doc.Add(new Field("segment", segment, Field.Store.YES, Field.Index.ANALYZED)); } // add the document to the index writer.AddDocument(doc); // commit changes to the index writer.Commit();In this example, we create a new SegString instance with a comma separator. We then create a new document with an ID and a message field. We use the SegString instance to split the message field into segments and add each segment to the document as a new field. Finally, we add the document to the index and commit the changes.