Call to IndexHelper.ClearPageIndexAsync(pageSetting) in loop does not work

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
2/15/2014 6:20:04 AM
Gravatar
Total Posts 7

Call to IndexHelper.ClearPageIndexAsync(pageSetting) in loop does not work

Hi Joe,

I was trying to clear indexing on pages of a page tree branch. Each call to IndexHelper.ClearPageIndexAsync(pageSetting) opens an instance of IndexReader in a new thread and deletes document as shown in below function

private static bool ClearPageIndex(PageSettings pageSettings)
 {
            if (pageSettings == null) return false;
            bool result = false;

            try
            {
                string indexPath = pageSettings.IndexPath;

                if (IndexReader.IndexExists(indexPath))
                {
                    IndexReader reader = IndexReader.Open(indexPath);
                    try
                    {
                        int tot = reader.NumDocs();
                        for (int i = 0; i < tot; i++)
                        {
                            Document doc = reader.Document(i);
                            if (doc.GetField("PageID").StringValue() ==
                                pageSettings.PageId.ToString(CultureInfo.InvariantCulture))
                            {
                                if (log.IsDebugEnabled) log.Debug("ClearPageIndex about to delete doc ");
                                try
                                {
                                    reader.DeleteDocument(i);
                                    result = true;
                                }
                                catch (IOException)
                                {
                                }
                            }
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
            }
            catch (ArgumentException ex)
            {
                log.Error(ex);
            }

            return result;
        }

I have resolved issue for 3 pages in loop by using lock and puting check !reader.IsDeleted(i) before deletion. But for more pages it still gives error "trying to delete already deleted document".

Any idea how to resolve above situation...

 

 

2/26/2014 1:55:25 AM
Gravatar
Total Posts 7

Re: Call to IndexHelper.ClearPageIndexAsync(pageSetting) in loop does not work

Can anybody help me to resolve above issue??

2/26/2014 7:14:14 AM
Gravatar
Total Posts 18439

Re: Call to IndexHelper.ClearPageIndexAsync(pageSetting) in loop does not work

Hi,

My advice is don't call it in a loop, that method spawns a new thread and we would not do that in a loop, it is never called in a loop from mojoportal code.

Keep in mind also that page objects are not really indexed at all, only content features that live on pages are indexed, pages are just containers for features and they have no content of their own.  So when a page is deleted we have to call the indexer for each feature and tell it to delete any index content for the feature that is one the given page id.

If you are writing some custom code to delete things from the index in a loop, you should just use code similar to code in the method IndexHelper.RemoveInfex(IndexItem, indexpath)

That is you create IndexingQueue objects which get serialized into the mp_IndexingQueue table, then call SiteUtils.QueueIndexing() one time after all the looping is done. This will spawn a single task to process the queue and delete the items.

Hope that helps,

Joe

3/8/2014 7:10:49 AM
Gravatar
Total Posts 7

Re: Call to IndexHelper.ClearPageIndexAsync(pageSetting) in loop does not work

Joe,

Thanks for your reply...

3/14/2014 6:56:19 AM
Gravatar
Total Posts 7

Re: Call to IndexHelper.ClearPageIndexAsync(pageSetting) in loop does not work

Hi Joe,

Your suggestion can lead to alternate solution. But I am able to resolve my issue on solution on my path after some R&D as follow that I would like share

private

static object my_lock = new object();

 private static bool ClearPageIndex(PageSettings pageSettings)
        {
            if (pageSettings == null) return false;
            bool result = false;

            lock (my_lock)
            {
                try
                {                  
                    string indexPath = pageSettings.IndexPath;

                    if (IndexReader.IndexExists(indexPath))
                    {
                   
                        IndexWriter wr = new IndexWriter(indexPath, new StandardAnalyzer());
                        try
                        {
                            wr.DeleteDocuments(new Term("PageID", pageSettings.PageId.ToString(CultureInfo.InvariantCulture)));                 
                        }
                        finally
                        {
                            wr.Close();                       
                        }
                    }
                }
                catch (ArgumentException ex)
                {
                    log.Error(ex);
                }
            }

            return result;
        }

You must sign in to post in the forums. This thread is closed to new posts.