Exemple #1
0
 // add/update/clear search index data
 public static void AddUpdateLuceneIndex(LuceneSearchModel sampleData)
 {
     AddUpdateLuceneIndex(new List<LuceneSearchModel> { sampleData });
 }
Exemple #2
0
        private static void _addToLuceneIndex(LuceneSearchModel searchModel, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term(AppConstants.LucId, searchModel.Id.ToString()));
            writer.DeleteDocuments(searchQuery);

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

            // add lucene fields mapped to db fields
            // Posts
            doc.Add(new Field(AppConstants.LucId, searchModel.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(AppConstants.LucPostContent, searchModel.PostContent, Field.Store.YES, Field.Index.ANALYZED));

            //Topics
            if (!string.IsNullOrEmpty(searchModel.TopicName))
            {
                doc.Add(new Field(AppConstants.LucTopicName, searchModel.TopicName, Field.Store.YES, Field.Index.ANALYZED));
            }
            if (!string.IsNullOrEmpty(searchModel.TopicTags))
            {
                doc.Add(new Field(AppConstants.LucTopicTags, searchModel.TopicTags, Field.Store.YES, Field.Index.ANALYZED));
            }
            doc.Add(new Field(AppConstants.LucTopicUrl, searchModel.TopicUrl, Field.Store.YES, Field.Index.NOT_ANALYZED));

            // Chnage the date so we can query in date order
            var dateValue = DateTools.DateToString(searchModel.DateCreated, DateTools.Resolution.MILLISECOND);
            doc.Add(new Field(AppConstants.LucDateCreated, dateValue, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(AppConstants.LucTopicId, searchModel.TopicId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));

            //User
            doc.Add(new Field(AppConstants.LucUsername, searchModel.Username, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field(AppConstants.LucUserId, searchModel.UserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));

            // add entry to index
            writer.AddDocument(doc);
        }
Exemple #3
0
 /// <summary>
 /// Add / Update an item in the index
 /// </summary>
 /// <param name="luceneSearchModel"></param>
 public void AddUpdate(LuceneSearchModel luceneSearchModel)
 {
     GoLucene.AddUpdateLuceneIndex(luceneSearchModel);
 }
Exemple #4
0
 /// <summary>
 /// Map a post to the Lucene Model
 /// </summary>
 /// <param name="post"></param>
 /// <returns></returns>
 public LuceneSearchModel MapToModel(Post post)
 {
     var model = new LuceneSearchModel
         {
             Id = post.Id,
             PostContent = post.PostContent,
             DateCreated = post.DateCreated,
             TopicId = post.Topic.Id,
             TopicUrl = post.Topic.NiceUrl,
             Username = post.User.UserName,
             UserId = post.User.Id
         };
     if(post.IsTopicStarter)
     {
         model.TopicName = post.Topic.Name;
     }
     return model;
 }
Exemple #5
0
 /// <summary>
 /// Map a post to the Lucene Model
 /// </summary>
 /// <param name="post"></param>
 /// <returns></returns>
 public LuceneSearchModel MapToModel(Post post)
 {
     var model = new LuceneSearchModel
         {
             Id = post.Id,
             PostContent = post.PostContent,
             DateCreated = post.DateCreated,
             TopicId = post.Topic.Id,
             TopicUrl = post.Topic.NiceUrl,
             TopicTags = post.Topic.Tags.Aggregate("", (current, tag) => current + " " + tag.Tag),
             Username = post.User.UserName,
             UserId = post.User.Id
         };
     if(post.IsTopicStarter)
     {
         model.TopicName = post.Topic.Name;
     }
     return model;
 }