public static void Add(LuceneIndexObject obj) { var _analyzer = new StandardAnalyzer(CurrentVersion); using (var _writer = new IndexWriter(Directory, _analyzer, IndexWriter.MaxFieldLength.UNLIMITED)) { Add(obj, _writer); _analyzer.Close(); _writer.Dispose(); } }
public static void Add(LuceneIndexObject obj, IndexWriter writer) { // remove older index entry var _searchQuery = new TermQuery(new Term("Id", obj.Id)); writer.DeleteDocuments(_searchQuery); // add new index entry var _doc = new Document(); // add lucene fields mapped to db fields _doc.Add(new Field("Id", obj.Id, Field.Store.YES, Field.Index.NOT_ANALYZED)); _doc.Add(new Field("Image", obj.Id, Field.Store.YES, Field.Index.NOT_ANALYZED)); _doc.Add(new Field("Name", obj.Name, Field.Store.YES, Field.Index.ANALYZED)); _doc.Add(new Field("Html", obj.Html, Field.Store.YES, Field.Index.ANALYZED)); // add entry to index writer.AddDocument(_doc); }