Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Aximili 177 posts 278 karma points
    Jun 17, 2011 @ 02:45
    Aximili
    0

    When is Document.AfterPublish executed?

    I am curious when AfterPublish is executed. I have this method

      private void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
      {
        ExamineManager.Instance.IndexProviderCollection["SiteSearchIndexer"].RebuildIndex(); // This doesn't index the latest change, must republish to index it
      }

    But the RebuildIndex() method still did not get the latest change I did immediately before publishing.

    That happens all the time. I have to publish twice for the index to include the latest change. Why does that happen? Is AfterPublish executed prior to data being saved...??

    Thanks in advance.

  • Richard Soeteman 4047 posts 12900 karma points MVP 2x
    Jun 17, 2011 @ 06:31
    Richard Soeteman
    0

    This is because the document is not yet added to the XML Cache at that stage. Use the AfterUpdateDocumentCache  event on the content class for that. Check out http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/overview-of-all-events for more info.

    But rebuilding the index after every publish, doesn't that cause performance problems?

    Thanks,

    Richard

  • Aximili 177 posts 278 karma points
    Jun 24, 2011 @ 03:27
    Aximili
    0

    Perfect! Thanks a lot Richard, I wasn't aware of that event.

    Otherwise, what would you suggest? If you don't do that, the search result will always be out of date and useless. We can't ask clients to manually rebuild the index everytime they publish, they will forget.

  • Richard Soeteman 4047 posts 12900 karma points MVP 2x
    Jun 24, 2011 @ 09:12
    Richard Soeteman
    0

    Hi,

    This event is always triggered afer a publish so no need to ask your client for that. It's just a different event.

    Cheers,

    Richard

  • Aximili 177 posts 278 karma points
    Jun 27, 2011 @ 02:47
    Aximili
    0

    What event is always triggered after a publish? What is just a different event? Do you mean the RebuildIndex()?

    I have moved the RebuildIndex() to AfterUpdateDocumentCache as you said. If I don't have RebuildIndex() anywhere, the index will never get updated, and search results will always be out of date.

    So what is your solution...? Sorry I still don't understand.

Please Sign in or register to post replies

Write your reply to:

Draft