示例#1
0
        protected virtual void UpdateIndex(BulkLoadContext context, ICollection <ItemChange> itemChanges,
                                           Database database, ISearchIndex index)
        {
            Job job = null;

            if (!context.ShouldUpdateIndex(index))
            {
                context.Log.Warn($"Skipping updating index '{index.Name}' because its empty.");
                return;
            }

            var touchedPercentage = (uint)Math.Ceiling((double)itemChanges.Count / Math.Max(1, index.Summary.NumberOfDocuments) * 100);

            if (context.IndexRebuildThresholdPercentage.HasValue &&
                touchedPercentage > context.IndexRebuildThresholdPercentage.Value)
            {
                context.Log.Info($"Rebuilding index '{index.Name}' because {touchedPercentage}% is changed.");
                job = IndexCustodian.FullRebuild(index);
            }
            else if (context.Destination != null &&
                     !itemChanges.Any(ic => ic.Deleted) &&   // Refresh doesn't do deletes.
                     context.IndexRefreshThresholdPercentage.HasValue &&
                     touchedPercentage > context.IndexRefreshThresholdPercentage.Value)
            {
                context.Log.Info($"Refreshing index '{index.Name}' from '{context.Destination.ItemPath}' because {touchedPercentage}% is changed.");
                job = IndexCustodian.Refresh(index, new SitecoreIndexableItem(database.GetItem(new ID(context.Destination.ItemId))));
            }
            else
            {
                var sitecoreIds = GetItemsToIndex(itemChanges, database);
                context.Log.Info($"Updating index '{index.Name}' with {sitecoreIds.Count} items.");
                job = IndexCustodian.IncrementalUpdate(index, sitecoreIds);
            }
            job.Wait();
        }
示例#2
0
        public virtual void RebuildCognitiveIndexes()
        {
            List <string> cogIndexes = new List <string>();
            var           nodes      = Sitecore.Configuration.Factory.GetConfigNodes("contentSearch/configuration/indexes/index");

            foreach (XmlNode n in nodes)
            {
                var id = n.Attributes?["id"];
                if (id == null || !id.Value.StartsWith("cognitive"))
                {
                    continue;
                }

                var dbNode = n.SelectSingleNode("locations/crawler/Database");
                var value  = dbNode?.FirstChild?.InnerText;
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                cogIndexes.Add(value);
            }

            foreach (var dbName in cogIndexes)
            {
                var searchIndex = ContentSearch.GetIndex(GetCognitiveIndexName(dbName));
                IndexCustodian.FullRebuild(searchIndex);
            }
        }
        public void Run(ITaskOutput output, NameValueCollection metaData)
        {
            // Create the standard users
            CreateSecurityAccounts.CreateAccounts();

            // Rebuild the core and master indexes
            IndexCustodian.FullRebuild(ContentSearchManager.GetIndex("sitecore_core_index"), true);
            IndexCustodian.FullRebuild(ContentSearchManager.GetIndex("sitecore_master_index"), true);
        }
示例#4
0
        void HandleTweet(ITweet tweet)
        {
            if ((from tag in tweet.Hashtags where tag.Text == HashtagTrigger select tag).Any())
            {
                Log.Info("Index rebuild triggered from Twitter by '{0}'".FormatWith(tweet.Creator.Name), this);
                CrawlingLog.Log.Info("Index rebuild triggered from Twitter by '{0}'".FormatWith(tweet.Creator.Name));

                if (IndexCustodian.IsIndexingPaused(m_index) || IndexCustodian.IsRebuilding(m_index))
                {
                    CrawlingLog.Log.Warn("Indexing call muted");
                    Log.Info("Indexing call muted", this);
                    return;
                }

                IndexCustodian.FullRebuild(m_index);
            }
        }
        public void RunPostDeployAction(XDocument deployedItems, IPostDeployActionHost host, string parameter)
        {
            string[] indexNames = this.GetContentSearchIndexes(parameter);
            foreach (var indexName in indexNames)
            {
                var index = ContentSearchManager.GetIndex(indexName.Trim());

                if (index == null)
                {
                    host.LogMessage("The Content Search Index with name {0} supplied does not exist.", indexName);
                    continue;
                }

                host.LogMessage("Rebuilding index {0}...", indexName);
                IndexCustodian.FullRebuild(index, true);
                host.LogMessage("Rebuild of index {0} complete", indexName);
            }
        }
        public override ConversationResponse Respond(LuisResult result, ItemContextParameters parameters, IConversation conversation)
        {
            var message = "";
            var index   = (string)conversation.Data[IndexKey];

            if (index == "All")
            {
                IndexCustodian.RebuildAll(new [] { IndexGroup.Experience });
                message = "All indexes are being rebuilt";
            }
            else
            {
                var searchIndex = ContentSearchWrapper.GetIndex(index);
                IndexCustodian.FullRebuild(searchIndex);
                message = $"The {index} index is being rebuilt";
            }

            return(ConversationResponseFactory.Create(message));
        }
示例#7
0
        public override ConversationResponse Respond(LuisResult result, ItemContextParameters parameters, IConversation conversation)
        {
            var message = "";
            var index   = (string)conversation.Data[IndexKey];

            if (index == AllOption)
            {
                IndexCustodian.RebuildAll(new [] { IndexGroup.Experience });
                message = Translator.Text("Chat.Intents.RebuildIndex.AllRebuiltMessage");
            }
            else
            {
                var searchIndex = ContentSearchWrapper.GetIndex(index);
                IndexCustodian.FullRebuild(searchIndex);
                message = string.Format(Translator.Text("Chat.Intents.RebuildIndex.RebuildIndexMessage"), index);
            }

            return(ConversationResponseFactory.Create(message));
        }
示例#8
0
 private void RebuildIndex()
 {
     try
     {
         var index = ContentSearchManager.GetIndex(_indexName);
         if (index != null)
         {
             IndexRebuilding.Visible = true;
             IndexCustodian.FullRebuild(index, true);
         }
         else
         {
             IndexNotFound.Visible = true;
         }
     }
     catch (Exception ex)
     {
         IndexRebuildError.Text    = ex.Message;
         IndexRebuildError.Visible = true;
     }
 }
示例#9
0
        public IHttpActionResult Rebuild([FromBody] string indexname)
        {
            if (!IsAuthenticated)
            {
                return(Unauthorized());
            }

            using (new UserSwitcher(Context.Site.Domain.GetFullName(this.ApiUser), false))
            {
                if (!Context.User.IsAdministrator)
                {
                    return(Unauthorized());
                }

                var index = ContentSearchManager.Indexes.SingleOrDefault(idx => idx.Name == indexname);

                var payload = new IndexingUpdate
                {
                    IndexName                = index.Name,
                    State                    = State.Started,
                    NumberOfDocuments        = index.Summary.NumberOfDocuments,
                    LastUpdated              = index.Summary.LastUpdated,
                    IndexRebuildMilliseconds = IndexHealthHelper.GetIndexRebuildTime(index.Name),
                    IndexRebuildTime         = IndexingEventHandler.BuildTime(index)
                };

                if (index.Group == IndexGroup.Experience || !ContentSearchManager.Locator.GetInstance <ISearchIndexSwitchTracker>().IsIndexOn(index.Name))
                {
                    payload.State = State.NotStarting;
                    return(new JsonResult <IndexingUpdate>(payload, new JsonSerializerSettings(), Encoding.UTF8, this));
                }
                else
                {
                    var job = IndexCustodian.FullRebuild(index, true);
                    payload.Job   = job.DisplayName;
                    payload.State = State.Started;
                    return(new JsonResult <IndexingUpdate>(payload, new JsonSerializerSettings(), Encoding.UTF8, this));
                }
            }
        }
示例#10
0
        private void RebuildIndex(string indexName)
        {
            try
            {
                Diagnostics.Log.Info(string.Format("Rebuilding index {0}", indexName), this);

                ISearchIndex index = ContentSearchManager.GetIndex(indexName);

                if (index != null)
                {
                    IndexCustodian.FullRebuild(index);

                    //while (IndexCustodian.IsRebuilding(index))
                    //{
                    //    Thread.Sleep(1000);
                    //}
                }
            }
            catch (Exception ex)
            {
                Diagnostics.Log.Error("Error Rebuilding Index", ex, this);
            }
        }
示例#11
0
        public IJob FullRebuild(ISearchIndex index, bool isRemote)
        {
            var job = (isRemote) ? IndexCustodian.FullRebuildRemote(index) : IndexCustodian.FullRebuild(index);

            return(job == null ? null : new SpeJob(job));
        }
        private void RebuildIndex(ISearchIndex index, bool isRemoteIndex = false)
        {
            if (IndexCustodian.IsRebuilding(index))
            {
                WriteVerbose($"Skipping full index rebuild for {index.Name} because it's already running.");
                var job = Sitecore.Jobs.JobManager.GetJob($"{"Index_Update"}_IndexName={index.Name}");

                if (job == null || !AsJob)
                {
                    return;
                }

                WriteVerbose($"Background job existed: {job.Name}");
                WriteObject(job);
            }
            else
            {
                WriteVerbose($"Starting full index rebuild for {index.Name}.");
                var job = (isRemoteIndex) ? IndexCustodian.FullRebuildRemote(index) : IndexCustodian.FullRebuild(index);

                if (job == null || !AsJob)
                {
                    return;
                }

                WriteVerbose($"Background job created: {job.Name}");
                WriteObject(job);
            }
        }
示例#13
0
 public virtual Job FullRebuild(ISearchIndex searchIndex)
 {
     return(IndexCustodian.FullRebuild(searchIndex));
 }