예제 #1
0
        /// <summary>
        /// Update the search index with the contents of the section.
        /// </summary>
        /// <param name="section"></param>
        public static void UpdateIndexFromSection(Section section)
        {
            // Get ModuleLoader from the container. This needs to happen explicit here because
            // this is a static method
            ModuleLoader moduleLoader = ContainerAccessorUtil.GetContainer()[typeof(ModuleLoader)] as ModuleLoader;
            if (moduleLoader == null)
            {
                throw new NullReferenceException("Unable to find the ModuleLoader instance");
            }
            string indexDir = HttpContext.Current.Server.MapPath(Config.GetConfiguration()["SearchIndexDir"]);
            IndexBuilder ib = new IndexBuilder(indexDir, false);

            ModuleBase module = moduleLoader.GetModuleFromSection(section);
            if (module is ISearchable)
            {
                ib.UpdateContentFromModule(module);
            }

            ib.Close();
        }
예제 #2
0
 private void BuildIndex()
 {
     string indexDir = Context.Server.MapPath(Config.GetConfiguration()["SearchIndexDir"]);
     IndexBuilder ib = new IndexBuilder(indexDir, true);
     IList sites = base.CoreRepository.GetAll(typeof(Site));
     foreach (Site site in sites)
     {
         foreach (Node node in site.RootNodes)
         {
             try
             {
                 BuildIndexByNode(node, ib);
             }
             catch (Exception ex)
             {
                 log.Error(String.Format("Indexing contents of Node {0} - {1} failed.", node.Id, node.Title), ex);
             }
         }
     }
     ib.Close();
 }
 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();
 }
예제 #4
0
        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("Unable to create Module for Section {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("Indexing contents of Section {0} - {1} failed.", section.Id, section.Title), ex);
                    }
                }
            }
            foreach (Node childNode in node.ChildNodes)
            {
                BuildIndexByNode(childNode, ib);
            }
        }