Example #1
0
        public virtual ContentIndexResult IndexContent(IContent content, bool includeChild = false)
        {
            SlimContentReader slimContentReader = new SlimContentReader(this._contentRepository, content.ContentLink, (c =>
            {
                return(includeChild);
            }));
            var listDocument = new List <SearchDocument>();

            while (slimContentReader.Next())
            {
                if (!slimContentReader.Current.ContentLink.CompareToIgnoreWorkID(ContentReference.RootPage))
                {
                    IVersionable current = slimContentReader.Current as IVersionable;
                    if (current == null || current.Status == VersionStatus.Published)
                    {
                        if (LuceneConfiguration.CanIndexContent(slimContentReader.Current))
                        {
                            var document = GetDocFromContent(slimContentReader.Current);
                            if (document != null)
                            {
                                listDocument.Add(document);
                            }
                        }
                    }
                }
            }
            _documentRepository.UpdateBatchIndex(listDocument);
            return(new ContentIndexResult());
        }
Example #2
0
 public virtual void RemoveContentIndex(IContent content, bool includeChild = false)
 {
     if (!ContentReference.IsNullOrEmpty(content?.ContentLink))
     {
         SlimContentReader slimContentReader = new SlimContentReader(this._contentRepository, content.ContentLink, (c =>
         {
             return(includeChild);
         }));
         var deletedList = new List <string>();
         while (slimContentReader.Next())
         {
             if (!ContentReference.IsNullOrEmpty(slimContentReader.Current?.ContentLink))
             {
                 if (!slimContentReader.Current.ContentLink.CompareToIgnoreWorkID(ContentReference.RootPage))
                 {
                     var allLanguageBranch = _contentRepository.GetLanguageBranches <IContent>(slimContentReader.Current.ContentLink);
                     foreach (var lang in allLanguageBranch)
                     {
                         deletedList.Add(SearchDocument.FormatDocumentId(lang));
                     }
                 }
             }
             _documentRepository.DeleteFromIndex(deletedList);
         }
     }
 }
Example #3
0
        public ContentIndexResult ReindexSiteForRecovery(IContent siteRoot)
        {
            SlimContentReader slimContentReader = new SlimContentReader(this._contentRepository, siteRoot.ContentLink, (c =>
            {
                return(true);
            }));
            var listDocument = new List <SearchDocument>();

            while (slimContentReader.Next())
            {
                if (!slimContentReader.Current.ContentLink.CompareToIgnoreWorkID(ContentReference.RootPage))
                {
                    IVersionable current = slimContentReader.Current as IVersionable;
                    if (current == null || current.Status == VersionStatus.Published)
                    {
                        if (LuceneConfiguration.CanIndexContent(slimContentReader.Current))
                        {
                            var document = GetDocFromContent(slimContentReader.Current);
                            if (document != null)
                            {
                                listDocument.Add(document);
                            }
                        }
                    }
                }
            }
            _documentRepository.ReindexSiteForRecovery(listDocument, siteRoot.ContentGuid);
            return(new ContentIndexResult());
        }
        public string IndexSite(List <int> siteStartPageIds)
        {
            var progress = new StringBuilder();

            progress.AppendLine("Start Indexing </br>");
            if (!LuceneConfiguration.Active)
            {
                progress.AppendLine("Lucene not activated </br>");
                return(progress.ToString());
            }
            foreach (var siteId in siteStartPageIds)
            {
                PageData siteRoot;
                if (_contentRepository.TryGet <PageData>(new ContentReference(siteId), out siteRoot))
                {
                    if (siteRoot == null)
                    {
                        continue;
                    }
                    try
                    {
                        SlimContentReader slimContentReader = new SlimContentReader(this._contentRepository, siteRoot.ContentLink, (c =>
                        {
                            return(true);
                        }));
                        while (slimContentReader.Next())
                        {
                            var currentContent = slimContentReader.Current;
                            if (currentContent != null && !currentContent.ContentLink.CompareToIgnoreWorkID(ContentReference.RootPage))
                            {
                                if (LuceneConfiguration.CanIndexContent(currentContent))
                                {
                                    _indexingHandler.ProcessRequest(new IndexRequestItem(currentContent));
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Error($"Lucene Index Site Error: {siteRoot.ContentLink.ID} - {siteRoot.Name}", e);
                        progress.AppendLine($"{siteRoot.ContentLink.ID} - {siteRoot.Name} index failed </br>");
                        continue;
                    }
                    progress.AppendLine($"Site: {siteRoot.ContentLink.ID} - {siteRoot.Name} indexed; </br>");
                }
            }
            progress.AppendLine("Indexing completed</br>");
            return(progress.ToString());
        }