コード例 #1
0
ファイル: SearchManager.cs プロジェクト: hdgardner/ECF
        /// <summary>
        /// Builds the index.
        /// </summary>
        /// <param name="rebuild">if set to <c>true</c> [rebuild].</param>
        public void BuildIndex(bool rebuild)
        {
            _IndexBuilderIndex = 1;
            _IndexBuilderCount = SearchConfiguration.Instance.Indexers.Count;
            foreach (IndexerDefinition indexer in SearchConfiguration.Instance.Indexers)
            {
                Logger.Debug(String.Format("Getting the type \"{0}\".", indexer.ClassName));
                ClassInfo classInfo = new ClassInfo(indexer.ClassName);
                Logger.Debug(String.Format("Creating instance of \"{0}\".", classInfo.Type.Name));
                ISearchIndexBuilder builder = ((ISearchIndexBuilder)classInfo.CreateInstance());
                builder.Manager = this;
                IndexBuilder buildIndexer = null;

                try
                {
                    string path = GetApplicationPath(indexer);
                    buildIndexer    = new IndexBuilder(path, rebuild, indexer.Name);
                    builder.Indexer = buildIndexer;
                    if (rebuild)
                    {
                        Logger.Info(String.Format("Starting new index build in \"{0}\" using \"{1}\" indexer.", path, indexer.Name));
                    }
                    else
                    {
                        Logger.Info(String.Format("Starting incremental index build in \"{0}\" using \"{1}\" indexer.", path, indexer.Name));
                    }

                    builder.BuildIndex(rebuild);
                    buildIndexer.SaveBuild(Status.Completed);
                    buildIndexer.Close(!buildIndexer.RebuildIndex);
                    Logger.Info(String.Format("Successfully finished index build in \"{0}\" using \"{1}\" indexer.", path, indexer.Name));
                }
                catch (Exception ex)
                {
                    if (buildIndexer != null)
                    {
                        buildIndexer.Close();
                    }

                    string msg             = String.Format("Build Failed using \"{0}\" indexer. \"{1}\"", indexer.Name, ex.Message);
                    IndexBuildException ne = new IndexBuildException(msg, ex);
                    Logger.Info(msg, ne);
                    throw ne;
                }
                finally
                {
                }
                _IndexBuilderIndex++;
            }
        }