Copied to clipboard

Flag this post as spam?

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


  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 02, 2011 @ 11:23
    Dirk De Grave
    0

    Best way to reindex a specific node using ReIndex()

    Hi,

    Could use some help on what to pass in as the first param to ReIndex() on de indexer object? It needs to be a XElement object, but only have .ToXml() available on the document object of the node that I'd like to reindex...

    I don't want to remove the node from the index and republish the node to make sure it makes it into the index again, seems like there should be a much simpler solution to this, right?

    Any ideas on how to do this?

     

    TIA,

    /Dirk

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    May 02, 2011 @ 12:13
    Damiaan
    1

    Just a guess out in the wild.

    XElement has a static .Parse method.  Can't you use that ?

     

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    May 02, 2011 @ 14:13
    Shannon Deminick
    1

    There are Extension methods in the Examine codebase to transform the umbraco objects into XElement objects. In the UmbracoExamine namespace there's extension methods called ToXElement on a Umbraco Content object.

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    May 02, 2011 @ 14:14
    Shannon Deminick
    0

    I realize this isn't the nicest API to deal with, its legacy now. Future versions of Examine will use a Dictionary object for simplicity

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 03, 2011 @ 09:14
    Dirk De Grave
    2

    Follow up on my solution... Shannon has put me in the right direction, altho I've been struggling quite a lot with in which order events (both Examine and my own) were fired. Lessons learnt!

    Here's what I finally came up with, but let me start by explaining what I was looking for in the first place.

    I've got a doc type A wih a multi node tree picker which works great, but makes it a bit harder if you also need to search on properties defined on another doc type B that are referenced by doc type A using the mntp property, so I decided to use the GatheringNodeData event to add some more fields to the Lucene index for this doc type A so I would only have to search my Lucene index for doc type A documents.

    All goes well, but that also means I needed to reindex all nodes of doc type A when a document of type B changed and was referenced by any of the doc A type documents.

    So, final solution which works great for my specific scenario is to build a GatheringNodeData event handler to add some more fields to the Lucene index for doc type A and use a AfterUpdateDocumentCache event handler for doc type B documents to find out what doc type A docs are referencing this document and reindex those doc type A documents using:

    ExamineManager.Instance.ReIndexNode(new Document(searchResult.Id).ToXDocument(false).Root, IndexTypes.Content);

    where searchResult.Id refers to the node id found using another Examine search and .ToXDocument() a extension method on the Content class. Don't forget to use the .Root property, otherwise you'll get xml errors and warnings and your Lucene index may get corrupt.

    Hope someone else will benefit from this solution.

     

    Cheers and thanks to all who've helped!

    /Dirk

     

     

     

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    May 03, 2011 @ 10:45
    Shannon Deminick
    0

    Nice work!!

  • Mike Taylor 155 posts 353 karma points
    Nov 11, 2011 @ 12:51
    Mike Taylor
    0

    I'm trying this, but am seeing duplicate entries when I use ReIndexNode like this...

    In my situation, when a child node ("book") is published, I also need it to update a custom field in the index entry corresponding to its parent node ("series").

    In my  GatheringNodeData event for the child nodes, I'm asking it to ReIndexNode on the parent node, but when the index is built, all the parent nodes ("series") appear twice in the index.

    What might be causing this?

    Mike

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Nov 12, 2011 @ 05:06
    Shannon Deminick
    0

    @Mike: are you using the latest Examine 1.x version ?

Please Sign in or register to post replies

Write your reply to:

Draft