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?
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.
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:
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.
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.
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
Just a guess out in the wild.
XElement has a static .Parse method. Can't you use that ?
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.
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
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:
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
Nice work!!
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
@Mike: are you using the latest Examine 1.x version ?
is working on a reply...