Ejemplo n.º 1
0
        public void OnItemProcessed(object sender, EventArgs args)
        {
            var arguments = args as ItemProcessedEventArgs;

            var context = arguments?.Context;

            Item item = context?.VersionToPublish;

            if (item == null)
            {
                return;
            }

            if (!this.indexingService.ItemShouldBeIndexed(item))
            {
                return;
            }

            if (context.Action == PublishAction.DeleteTargetItem)
            {
                IndexingQueue.Delete(item);
            }
            else if (context.Action != PublishAction.Skip)
            {
                IndexingQueue.Add(item);
            }
        }
Ejemplo n.º 2
0
        public void OnItemDeleted(object sender, EventArgs args)
        {
            Item item = Event.ExtractParameter(args, 0) as Item;

            if (item == null)
            {
                return;
            }

            if (!this.indexingService.ItemShouldBeIndexed(item))
            {
                return;
            }

            IndexingQueue.Delete(item);
        }
Ejemplo n.º 3
0
        private void ProcessQueue(DataTable q, int siteId, string indexPath)
        {
            rowsProcessed = 0;
            rowsToProcess = q.Rows.Count;

            // first process deletes with reader
            try
            {
                using (Lucene.Net.Store.Directory searchDirectory = IndexHelper.GetDirectory(siteId))
                {
                    using (IndexReader reader = IndexReader.Open(searchDirectory, false))
                    {
                        foreach (DataRow row in q.Rows)
                        {
                            Term term = new Term("Key", row["ItemKey"].ToString());
                            try
                            {
                                reader.DeleteDocuments(term);
                                log.Debug("reader.DeleteDocuments(term) for Key " + row["ItemKey"].ToString());
                            }
                            catch (Exception ge)
                            {
                                // TODO: monitor what real exceptions if any occur and then
                                // change this catch to catch only the expected ones
                                // instead of non specific exception
                                log.Error(ge);
                            }

                            bool removeOnly = Convert.ToBoolean(row["RemoveOnly"]);
                            if (removeOnly)
                            {
                                Int64 rowId = Convert.ToInt64(row["RowId"]);
                                IndexingQueue.Delete(rowId);
                            }


                            if (DateTime.UtcNow > nextStatusUpdateTime)
                            {
                                // don't mark as complete because there may be more qu items
                                //for different index paths in a multi site installation
                                bool markAsComplete = false;
                                ReportStatus(markAsComplete);
                            }
                        }
                    }
                }
            }
            catch (System.IO.IOException ex)
            {
                log.Info("IndexWriter swallowed exception this is not unexpected if building or rebuilding the search index ", ex);
                errorCount += 1;
            }
            catch (TypeInitializationException ex)
            {
                log.Info("IndexWriter swallowed exception ", ex);
                errorCount += 1;
            }


            // next add items with writer
            using (Lucene.Net.Store.Directory searchDirectory = IndexHelper.GetDirectory(siteId))
            {
                using (IndexWriter indexWriter = GetWriter(siteId, searchDirectory))
                {
                    if (indexWriter == null)
                    {
                        log.Error("failed to get IndexWriter for path: " + indexPath);
                        errorCount += 1;
                        return;
                    }

                    foreach (DataRow row in q.Rows)
                    {
                        bool removeOnly = Convert.ToBoolean(row["RemoveOnly"]);
                        if (!removeOnly)
                        {
                            try
                            {
                                IndexItem indexItem
                                    = (IndexItem)SerializationHelper.DeserializeFromString(typeof(IndexItem), row["SerializedItem"].ToString());
                                // if the content is locked down to only admins it is a special case
                                // we just won't add it to the search index
                                // because at search time we avoid the role check for all admins, content admins and siteeditors
                                // we don't have a good way to prevent content admins and site editors from seeing the content
                                // in search
                                if ((indexItem.ViewRoles != "Admins;") && (indexItem.ModuleViewRoles != "Admins;"))
                                {
                                    if (indexItem.ViewPage.Length > 0)
                                    {
                                        Document doc = GetDocument(indexItem);
                                        WriteToIndex(doc, indexWriter);
                                        log.Debug("called WriteToIndex(doc, indexWriter) for key " + indexItem.Key);
                                    }
                                }

                                Int64 rowId = Convert.ToInt64(row["RowId"]);
                                IndexingQueue.Delete(rowId);
                            }
                            catch (Exception ex)
                            {
                                log.Error(ex);
                            }
                        }

                        if (DateTime.UtcNow > nextStatusUpdateTime)
                        {
                            // don't mark as complete because there may be more qu items
                            //for different index paths in a multi site installation
                            bool markAsComplete = false;
                            ReportStatus(markAsComplete);
                        }
                    }

                    try
                    {
                        indexWriter.Optimize();
                    }
                    catch (System.IO.IOException ex)
                    {
                        log.Error(ex);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void ProcessQueue(DataTable q, string indexPath)
        {
            rowsProcessed = 0;
            rowsToProcess = q.Rows.Count;

            // first process deletes with reader
            try
            {
                IndexReader reader = IndexReader.Open(indexPath);

                foreach (DataRow row in q.Rows)
                {
                    Term term = new Term("Key", row["ItemKey"].ToString());
                    try
                    {
                        reader.DeleteDocuments(term);
                        log.Debug("reader.DeleteDocuments(term) for Key " + row["ItemKey"].ToString());
                    }
                    catch (Exception ge)
                    {
                        // TODO: monitor what real exceptions if any occur and then
                        // change this catch to catch only the expected ones
                        // instead of non specific exception
                        log.Error(ge);
                    }

                    bool removeOnly = Convert.ToBoolean(row["RemoveOnly"]);
                    if (removeOnly)
                    {
                        Int64 rowId = Convert.ToInt64(row["RowId"]);
                        IndexingQueue.Delete(rowId);
                    }


                    if (DateTime.UtcNow > nextStatusUpdateTime)
                    {
                        // don't mark as complete because there may be more qu items
                        //for different index paths in a multi site installation
                        bool markAsComplete = false;
                        ReportStatus(markAsComplete);
                    }
                }

                reader.Close();
            }
            catch (IOException ex)
            {
                log.Info("IndexWriter swallowed exception this is not unexpected if building or rebuilding the search index ", ex);
                errorCount += 1;
            }
            catch (TypeInitializationException ex)
            {
                log.Info("IndexWriter swallowed exception ", ex);
                errorCount += 1;
            }


            // next add items with writer
            IndexWriter indexWriter = GetWriter(indexPath);

            if (indexWriter == null)
            {
                log.Error("failed to get IndexWriter for path: " + indexPath);
                errorCount += 1;
                return;
            }

            foreach (DataRow row in q.Rows)
            {
                bool removeOnly = Convert.ToBoolean(row["RemoveOnly"]);
                if (!removeOnly)
                {
                    try
                    {
                        IndexItem indexItem
                            = (IndexItem)SerializationHelper.DeserializeFromString(typeof(IndexItem), row["SerializedItem"].ToString());

                        Document doc = GetDocument(indexItem);
                        WriteToIndex(doc, indexWriter);
                        log.Debug("called WriteToIndex(doc, indexWriter) for key " + indexItem.Key);
                        Int64 rowId = Convert.ToInt64(row["RowId"]);
                        IndexingQueue.Delete(rowId);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }

                if (DateTime.UtcNow > nextStatusUpdateTime)
                {
                    // don't mark as complete because there may be more qu items
                    //for different index paths in a multi site installation
                    bool markAsComplete = false;
                    ReportStatus(markAsComplete);
                }
            }

            try
            {
                indexWriter.Optimize();
            }
            catch (IOException ex)
            {
                log.Error(ex);
            }

            try
            {
                indexWriter.Close();
            }
            catch (IOException ex)
            {
                log.Error(ex);
            }
        }