/// <summary> /// Maps database fields from incoming data source to the Lucene class Document /// and adds it to the search index. String or text properties are marked as /// ANALYZED, and int or single value properties are marked as NON_ANALYZED. /// </summary> /// <param name="data"></param> /// <param name="writer"></param> private static void AddToLuceneIndex(LuceneData data, IndexWriter writer) { if (data == null) { return; } // removing old index query var query = new TermQuery(new Term("Id", data.Id.ToString())); writer.DeleteDocuments(query); // adding new index entry var document = new Document(); // adding lucene fields and mapping them to db fields document.Add(new Field("Id", data.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); document.Add(new Field("InternalId", data.InternalId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); document.Add(new Field("PubDate", data.PubDate.ToString(), Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field("Author", data.Author, Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field("Title", data.Title, Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field("Type", data.Type, Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field("Tags", data.Tags, Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field("Link", data.Link, Field.Store.YES, Field.Index.NOT_ANALYZED)); document.Add(new Field("Description", data.Description, Field.Store.YES, Field.Index.ANALYZED)); // adding entry to index writer.AddDocument(document); }
/// <summary> /// Adds a single record to the Lucene search index. /// </summary> /// <param name="data"></param> public static void AddUpdateLuceneIndex(LuceneData data) { AddUpdateLuceneIndex(new List <LuceneData> { data }); }