private void BuildIndexByNode(Node node, IndexBuilder ib)
        {
            foreach (Section section in node.Sections)
            {
                ModuleBase module = null;
                try
                {
                    module = base.ModuleLoader.GetModuleFromSection(section);
                }
                catch (Exception ex)
                {
                    log.Error(String.Format("Không thể khởi động phân hệ cho vùng phân hệ {0} - {1}.", section.Id, section.Title), ex);
                }

                if (module is ISearchable)
                {
                    ISearchable searchableModule = (ISearchable)module;
                    try
                    {
                        foreach (SearchContent sc in searchableModule.GetAllSearchableContent())
                        {
                            ib.AddContent(sc);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(String.Format("Dựng bảng nội dung cho vùng {0} - {1} thất bại.", section.Id, section.Title), ex);
                    }
                }
            }
            foreach (Node childNode in node.ChildNodes)
            {
                BuildIndexByNode(childNode, ib);
            }
        }
        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();
        }
예제 #3
0
        /// <summary>
        /// Rebuild the full-text index.
        /// </summary>
        /// <param name="searchableModules">A list of (legacy) searchable modules in the installation.</param>
        public void RebuildIndex(IEnumerable<ISearchable> searchableModules)
        {
            Site currentSite = this._cuyahogaContextProvider.GetContext().CurrentSite;
            string indexDirectory = GetIndexDirectory();

            using (IndexBuilder indexBuilder = new IndexBuilder(indexDirectory, true, this._textExtractor))
            {
                // Add all content items
                var contentItemsToIndex = this._contentItemService.FindContentItemsBySite(currentSite);
                foreach (IContentItem contentItem in contentItemsToIndex)
                {
                    if (contentItem is ISearchableContent)
                    {
                        try
                        {
                            indexBuilder.AddContent(contentItem);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(string.Format("Error while indexing ContentItem with id {0}", contentItem.Id), ex);
                            throw;
                        }
                    }
                }

                // Add legacy searchable content
                if (searchableModules != null)
                {
                    foreach (ISearchable searchableModule in searchableModules)
                    {
                        foreach (SearchContent searchContent in searchableModule.GetAllSearchableContent())
                        {
                            try
                            {
                                indexBuilder.AddContent(searchContent);
                            }
                            catch (Exception ex)
                            {
                                Logger.Error(string.Format("Indexing of legacy searchContent item with path {0} failed.", searchContent.Path),
                                             ex);
                                throw;
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Rebuild the full-text index.
        /// </summary>
        /// <param name="contentItemsToIndex"></param>
        public void RebuildIndex(Site site, IEnumerable<IContentItem> contentItemsToIndex)
        {
            //Site currentSite = this._cuyahogaContextProvider.GetContext().CurrentSite;
             string indexDirectory = GetIndexDirectoryBySite(site);
             log.DebugFormat("SearchService.RebuildIndex: Site: {0}, indexDirectory = {1}", site.Name, indexDirectory);

             using (IndexBuilder indexBuilder = new IndexBuilder(indexDirectory, true, this._textExtractor))
             {
            // Add all content items
            //var contentItemsToIndex = this._contentItemService.FindAllBySite(currentSite);
            foreach (IContentItem contentItem in contentItemsToIndex)
            {
               // Index ONLY published items
               if (contentItem.PublishedDate.HasValue && contentItem is ISearchableContent)
               {
                  try
                  {
                     indexBuilder.AddContent(contentItem);
                  }
                  catch (Exception ex)
                  {
                     log.Error(string.Format("SearchService.FindContent: Error while indexing ContentItem with id {0}", contentItem.Id), ex);
                     throw;
                  }
               }
            }

            log.Debug("SearchService.FindContent: Optimizing index...");
            indexBuilder.Optimize();
             }
        }