Пример #1
0
        /// <summary>
        /// create document from SampleData
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private static Document CreateDocument(SampleData obj)
        {
            // add lucene fields mapped to db fields
            var doc = new Document();

            var f = new Field("ArtNo", obj.ArtNo, Field.Store.NO, Field.Index.ANALYZED);
            f.SetBoost(2F);
            doc.Add(f);

            f = new Field("Id", obj.Id.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED);
            f.SetBoost(1);
            doc.Add(f);

            f = new Field("Name", obj.Name, Field.Store.NO, Field.Index.ANALYZED);
            f.SetBoost(.1F);
            doc.Add(f);

            f = new Field("NameWithWiteSpace", obj.Name.RemoveSymbols(" "), Field.Store.NO, Field.Index.ANALYZED);
            f.SetBoost(.1F);
            doc.Add(f);

            f = new Field("NameWithWiteSpaceExt", obj.Name.RemoveSymbols(" ").RemoveSymvolsExt(" "), Field.Store.NO, Field.Index.ANALYZED);
            f.SetBoost(.1F);
            doc.Add(f);

            return doc;
        }
Пример #2
0
 public static void AddUpdateLuceneIndex(SampleData sampleData)
 {
     AddUpdateLuceneIndex(new List<SampleData> { sampleData });
 }
Пример #3
0
 /// <summary>
 /// Add document into index, delete if there was same term
 /// </summary>
 /// <param name="sampleData"></param>
 /// <param name="writer"></param>
 private static void AddToLuceneIndex(SampleData sampleData, IndexWriter writer)
 {
     // remove older index entry
     var searchQuery = new TermQuery(new Term("Id", sampleData.Id.ToString(CultureInfo.InvariantCulture)));
     writer.DeleteDocuments(searchQuery);
     // add new index entry
     var doc = CreateDocument(sampleData);
     // add entry to index
     writer.AddDocument(doc);
 }