public void DeleteContent(SearchContent searchContent) { using (IndexBuilder indexBuilder = CreateIndexBuilder()) { indexBuilder.DeleteContent(searchContent); } }
/// <summary> /// Add content to be indexed. /// </summary> /// <param name="searchContent"></param> public void AddContent(SearchContent searchContent) { if (this._indexWriter == null) { InitIndexWriter(); } this._indexWriter.AddDocument(BuildDocumentFromSearchContent(searchContent)); }
public SearchContent[] GetAllSearchableContent() { StaticHtmlContent shc = GetContent(); if (shc != null) { SearchContent[] searchContents = new SearchContent[1]; searchContents[0] = StaticHtmlContentToSearchContent(shc); return searchContents; } else { return new SearchContent[0]; } }
/// <summary> /// Delete existing content from the search index. /// </summary> /// <param name="searchContent"></param> public void DeleteContent(SearchContent searchContent) { if (this._rebuildIndex) { throw new InvalidOperationException("Cannot delete documents when rebuilding the index."); } else { this._indexWriter.Close(); this._indexWriter = null; // The path uniquely identifies a document in the index. Term term = new Term("path", searchContent.Path); IndexReader rdr = IndexReader.Open(this._indexDirectory); rdr.Delete(term); rdr.Close(); } }
private SearchContent AlternateContentToSearchContent(AlternateContent shc) { SearchContent sc = new SearchContent(); sc.Title = shc.Section.Title; sc.Summary = Text.TruncateText(shc.Content, 200); // trunctate the summary to 200 chars sc.Contents = shc.Content; sc.Author = shc.ModifiedBy.FullName; sc.ModuleType = shc.Section.ModuleType.Name; sc.Path = this.SectionUrl; sc.Category = String.Empty; sc.Site = shc.Section.Node.Site.Name; sc.DateCreated = shc.UpdateTimestamp; sc.DateModified = shc.UpdateTimestamp; sc.SectionId = shc.Section.Id; return sc; }
private SearchContent CreateSearchContent(string category, ICategory node, CatalogueUrlHelper urlHelper) { SearchContent sc = new SearchContent(); sc.Title = node.Name; sc.Contents = node.Description; sc.Author = "simon"; sc.ModuleType = this.Section.ModuleType.Name; sc.Path = urlHelper.GetCatalogueNodeUrl(node); sc.Category = category; sc.Site = (this.Section.Node != null ? this.Section.Node.Site.Name : String.Empty); sc.DateCreated = DateTime.Now; sc.DateModified = DateTime.Now; sc.SectionId = this.Section.Id; if (sc.Title == null || sc.Title.Length == 0) { sc.Title = "NODE " + node.NodeID; } if (sc.Contents == null || sc.Contents.Length == 0) { sc.Contents = "Desc " + (sc.Title); } sc.Summary = sc.Contents; return sc; }
private SearchContent CreateSearchContentName(string category, IProductSummary product, CatalogueUrlHelper urlHelper) { SearchContent sc = new SearchContent(); sc.Title = product.Name; sc.Contents = product.Name; sc.Author = "simon"; sc.ModuleType = this.Section.ModuleType.Name; sc.Path = urlHelper.GetProductUrl(product); sc.Category = category; sc.Site = (this.Section.Node != null ? this.Section.Node.Site.Name : String.Empty); sc.DateCreated = DateTime.Now; sc.DateModified = DateTime.Now; sc.SectionId = this.Section.Id; if (sc.Title == null || sc.Title.Length == 0) { sc.Title = product.Name; } if (sc.Contents == null || sc.Contents.Length == 0) { sc.Contents = "Item " + (sc.Title); } sc.Summary = sc.Contents; return sc; }
private Document BuildDocumentFromSearchContent(SearchContent searchContent) { Document doc = new Document(); doc.Add(Field.Text("title", searchContent.Title)); doc.Add(Field.Text("summary", searchContent.Summary)); doc.Add(Field.UnStored("contents", searchContent.Contents)); doc.Add(Field.Text("author", searchContent.Author)); doc.Add(Field.Keyword("moduletype", searchContent.ModuleType)); doc.Add(Field.Keyword("path", searchContent.Path)); doc.Add(Field.Keyword("category", searchContent.Category)); doc.Add(Field.Keyword("site", searchContent.Site)); doc.Add(Field.Keyword("datecreated", searchContent.DateCreated.ToString("u"))); doc.Add(Field.Keyword("datemodified", searchContent.DateModified.ToString("u"))); doc.Add(Field.UnIndexed("sectionid", searchContent.SectionId.ToString())); return doc; }
/// <summary> /// Update existing content in the search index. /// </summary> /// <param name="searchContent"></param> public void UpdateContent(SearchContent searchContent) { if (this._rebuildIndex) { throw new InvalidOperationException("Cannot update documents when rebuilding the index."); } else { // First delete the old content DeleteContent(searchContent); // Now add the content again AddContent(searchContent); } }
private void IndexContent(SearchContent searchContent, IndexAction action) { switch (action) { case IndexAction.Create: this._searchService.AddContent(searchContent); break; case IndexAction.Update: this._searchService.UpdateContent(searchContent); break; case IndexAction.Delete: this._searchService.DeleteContent(searchContent); break; } }
private void IndexContent(SearchContent searchContent, IndexAction action) { // Index string indexDir = Context.Server.MapPath(Config.GetConfiguration()["SearchIndexDir"]); IndexBuilder ib = new IndexBuilder(indexDir, false); switch (action) { case IndexAction.Create: ib.AddContent(searchContent); break; case IndexAction.Update: ib.UpdateContent(searchContent); break; case IndexAction.Delete: ib.DeleteContent(searchContent); break; } ib.Close(); }
private Document BuildDocumentFromSearchContent(SearchContent searchContent) { Document doc = new Document(); doc.Add(new Field("title", searchContent.Title, Field.Store.YES, Field.Index.TOKENIZED)); doc.Add(new Field("summary", searchContent.Summary, Field.Store.YES, Field.Index.TOKENIZED)); doc.Add(new Field("contents", searchContent.Contents, Field.Store.NO, Field.Index.TOKENIZED)); doc.Add(new Field("author", searchContent.Author, Field.Store.YES, Field.Index.TOKENIZED)); doc.Add(new Field("moduletype", searchContent.ModuleType, Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("path", searchContent.Path, Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("category", searchContent.Category, Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("site", searchContent.Site, Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("datecreated", searchContent.DateCreated.ToString("u"), Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("datemodified", searchContent.DateModified.ToString("u"), Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("sectionid", searchContent.SectionId.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); return doc; }
private SearchContent ArticleToSearchContent(Article article) { SearchContent sc = new SearchContent(); sc.Title = article.Title; if (article.Summary == null || article.Summary == String.Empty) { sc.Summary = Text.TruncateText(article.Content, 200); // truncate summary to 200 chars } else { sc.Summary = article.Summary; } sc.Contents = article.Content; sc.Author = article.ModifiedBy.FullName; sc.ModuleType = this.Section.ModuleType.Name; sc.Path = this.SectionUrl + "/" + article.Id; // article ID has to be added as pathinfo parameter. sc.Category = (article.Category != null ? article.Category.Title : sc.Category = String.Empty); sc.Site = (this.Section.Node != null ? this.Section.Node.Site.Name : String.Empty); sc.DateCreated = article.DateCreated; sc.DateModified = article.DateModified; sc.SectionId = this.Section.Id; return sc; }
/// <summary> /// Create an IndexEventArgs class. /// </summary> /// <param name="searchContent">The content that needs to be moved around.</param> public IndexEventArgs(SearchContent searchContent) { this._searchContent = searchContent; }