/// <summary> /// Deletes from index. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="id">The id.</param> public void DeleteFromIndex(ITransaction transaction, string id) { SearchUpdateContext tranContext = transaction.TransactionContext as SearchUpdateContext; if (tranContext == null) { throw new Exception("SearchUpdateContext not part of ITransaction!"); } tranContext.IndexWriter.DeleteDocuments(new TermQuery(new Term(SearchResult.IdField, id))); }
/// <summary> /// Indexes the static text. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="staticText">The static text.</param> public void IndexStaticText(ITransaction transaction, StaticTextCRUDModel staticText) { SearchUpdateContext tranContext = transaction.TransactionContext as SearchUpdateContext; if (tranContext == null) { throw new Exception("SearchUpdateContext not part of ITransaction!"); } Document doc = new Document(); doc.Add(new Field(SearchResult.IdField, staticText.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(SearchResult.TypeField, SearchResult.StaticTextType, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Title", staticText.Title, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Text", RemoveTags(staticText.Text), Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field("Published", DateTools.DateToString(staticText.PublishDate, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Date", DateTools.DateToString(staticText.ChangeDate, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.Add(new Field("User", staticText.Creator.Name, Field.Store.NO, Field.Index.ANALYZED)); doc.SetBoost(5F); tranContext.IndexWriter.AddDocument(doc); }
/// <summary> /// Indexes the twitter status. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="status">The status.</param> public void IndexTwitterStatus(ITransaction transaction, TwitterStatus status) { SearchUpdateContext tranContext = transaction.TransactionContext as SearchUpdateContext; if (tranContext == null) { throw new Exception("SearchUpdateContext not part of ITransaction!"); } Document doc = new Document(); doc.Add(new Field(SearchResult.IdField, status.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(SearchResult.TypeField, SearchResult.TwitterStatusType, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Title", string.Empty, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Text", RemoveTags(status.Text), Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field("Published", DateTools.DateToString(status.CreatedDate, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Date", DateTools.DateToString(status.CreatedDate, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.Add(new Field("User", status.User + " " + status.RetweetUser, Field.Store.NO, Field.Index.ANALYZED)); doc.SetBoost(3F); tranContext.IndexWriter.AddDocument(doc); }
/// <summary> /// Indexes the comment. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="comment">The comment.</param> public void IndexComment(ITransaction transaction, CommentCRUDModel comment) { SearchUpdateContext tranContext = transaction.TransactionContext as SearchUpdateContext; if (tranContext == null) { throw new Exception("SearchUpdateContext not part of ITransaction!"); } Document doc = new Document(); doc.Add(new Field(SearchResult.IdField, comment.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(SearchResult.TypeField, SearchResult.CommentType, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Title", comment.Name, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Text", RemoveTags(comment.Text), Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field("Published", DateTools.DateToString(comment.ChangeDate, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Date", DateTools.DateToString(comment.ChangeDate, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); var user = comment.ChangeUser != null ? comment.ChangeUser.Name : comment.AnonymousName; doc.Add(new Field("User", user, Field.Store.NO, Field.Index.ANALYZED)); tranContext.IndexWriter.AddDocument(doc); }
/// <summary> /// Indexes the rss item. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="rssItem">The RSS item.</param> public void IndexRssItem(ITransaction transaction, RssItemCRUDModel rssItem) { SearchUpdateContext tranContext = transaction.TransactionContext as SearchUpdateContext; if (tranContext == null) { throw new Exception("SearchUpdateContext not part of ITransaction!"); } Document doc = new Document(); doc.Add(new Field(SearchResult.IdField, rssItem.FeedItemId, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(SearchResult.TypeField, SearchResult.RssItemType, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Title", rssItem.Title, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Text", rssItem.Text, Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field("Published", DateTools.DateToString(rssItem.Published, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Date", DateTools.DateToString(rssItem.Published, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.Add(new Field("User", rssItem.Author, Field.Store.NO, Field.Index.ANALYZED)); doc.SetBoost(3F); tranContext.IndexWriter.AddDocument(doc); }