Extending Examine by canceling the GatheringNodeData event
I'm working on a project that is using Umbraco containing two websites. I want to make a search for one of the sites that is not indexing the other website. I've created the extension showed below.
On the GatherNodeData event my extension comes in
I check if I'm dealing with Content and if the path attibute is present
With my custom Helper I only check if the NodeTypeAlias name mathes "CorporateHome" in the path
If it isn't I cancel the event
Here comes the big question:
When I cancel the GatherNodeData event is this only for the current node or the whole proces of indexing?
public class CancelIndexerOnNonCorporateContent : ApplicationBase { /// <summary> /// Initializes a new instance of the <see cref="CancelIndexerOnWoningWebsite"/> class. /// </summary> public CancelIndexerOnNonCorporateContent() { ExamineManager.Instance.IndexProviderCollection["CorporateContentIndexer"].GatheringNodeData += CancelIndexerOnNonCorporateContent_GatheringNodeData; }
/// <summary> /// Handles the GatheringNodeData event of the CancelIndexerOnNonCorporateContent control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Examine.IndexingNodeDataEventArgs"/> instance containing the event data.</param> private void CancelIndexerOnNonCorporateContent_GatheringNodeData(object sender, IndexingNodeDataEventArgs e) { if (e.IndexType == "Content" && e.Node.Attribute("path") != null) { string[] pathIds = e.Node.Attribute("path").Value.Split(','); bool isInCorporatePath = pathIds.Where(i => UmbracoHelper.GetNodeTypeAlias(Convert.ToInt32(i)) == "CorporateHome").Any();
if (!isInCorporatePath) { e.Cancel = true; } } } }
I found a solution for the problem. The cancelation of the GatherNodeData has no effect on the indexing because it's too late. You can use the NodeIndexing event instead. Because there is no option to use the NodeFactoy in this thread you can use the umbraco.cms.businesslogic.web.Document instead. The only disadvantage of using this class is that you use the database for each query.
So here is the extension to cancel an indexer if a certain document is nested in a certain ContentType with a givven alias.
public class CancelIndexerOnNonCorporateContent : ApplicationBase { /// <summary> /// Initializes a new instance of the <see cref="CancelIndexerOnWoningWebsite"/> class. /// </summary> public CancelIndexerOnNonCorporateContent() { ExamineManager.Instance.IndexProviderCollection["CorporateContentIndexer"].NodeIndexing += CancelIndexerOnNonCorporateContent_NodeIndexing; }
/// <summary> /// Handles the NodeIndexing event of the CancelIndexerOnNonCorporateContent control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Examine.IndexingNodeEventArgs"/> instance containing the event data.</param> private static void CancelIndexerOnNonCorporateContent_NodeIndexing(object sender, IndexingNodeEventArgs e) { if (e.IndexType == "content" && e.Fields.ContainsKey("path")) { string[] pathIds = e.Fields["path"].Split(','); bool isInCorporatePath = pathIds.Where(i => GetDocumentContentTypeAlias(Convert.ToInt32(i)) == "CorporateHome").Any();
Extending Examine by canceling the GatheringNodeData event
I'm working on a project that is using Umbraco containing two websites. I want to make a search for one of the sites that is not indexing the other website. I've created the extension showed below.
Here comes the big question:
When I cancel the GatherNodeData event is this only for the current node or the whole proces of indexing?
I found a solution for the problem. The cancelation of the GatherNodeData has no effect on the indexing because it's too late. You can use the NodeIndexing event instead. Because there is no option to use the NodeFactoy in this thread you can use the umbraco.cms.businesslogic.web.Document instead. The only disadvantage of using this class is that you use the database for each query.
So here is the extension to cancel an indexer if a certain document is nested in a certain ContentType with a givven alias.
is working on a reply...