Пример #1
0
        private static void _addToLuceneIndex(LuceneBookModel bookData, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term("PostId", bookData.PostId.ToString(CultureInfo.InvariantCulture)));
            writer.DeleteDocuments(searchQuery);

            // add new index entry
            var bookDocument = new Document();

            // add lucene fields mapped to db fields
            bookDocument.Add(new Field("PostId",
                bookData.PostId.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED));

            if (bookData.Author != null)
            {
                bookDocument.Add(new Field("Author", bookData.Author, Field.Store.YES, Field.Index.ANALYZED,
                    Field.TermVector.WITH_POSITIONS_OFFSETS));
            }
            if (bookData.Title != null)
            {
                bookDocument.Add(new Field("Title", bookData.Title, Field.Store.YES, Field.Index.ANALYZED,
                    Field.TermVector.WITH_POSITIONS_OFFSETS));
            }
            if (bookData.Name != null)
            {
                bookDocument.Add(new Field("Name", bookData.Name, Field.Store.YES, Field.Index.ANALYZED,
                    Field.TermVector.WITH_POSITIONS_OFFSETS) { Boost = 3 });
            }
            if (bookData.Publisher != null)
            {
                bookDocument.Add(new Field("Publisher", bookData.Publisher, Field.Store.YES, Field.Index.ANALYZED,
                    Field.TermVector.WITH_POSITIONS_OFFSETS));
            }
            if (bookData.ISBN != null)
            {
                bookDocument.Add(new Field("ISBN", bookData.ISBN, Field.Store.YES, Field.Index.ANALYZED,
                    Field.TermVector.WITH_POSITIONS_OFFSETS));
            }
            if (bookData.Description != null)
            {
                bookDocument.Add(new Field("Description", bookData.Description, Field.Store.YES, Field.Index.ANALYZED,
                    Field.TermVector.WITH_POSITIONS_OFFSETS));
            }

            // add entry to index
            writer.AddDocument(bookDocument);
        }
Пример #2
0
 public static void AddUpdateLuceneIndex(LuceneBookModel bookData)
 {
     AddUpdateLuceneIndex(new List<LuceneBookModel> { bookData });
 }