here is my follow-up. I tried to solve the problem with an event handler:
public class ExamineEvents : ApplicationBase { private const string myIndexerName = "MyIndexerName"; private BaseIndexProvider myIndexer; private int parentId;
public ExamineEvents() { myIndexer = ExamineManager.Instance.IndexProviderCollection[myIndexerName]; myIndexer.NodesIndexed += new EventHandler<IndexedNodesEventArgs>(myIndexer_NodesIndexed);
void myIndexer_NodesIndexed(object sender, IndexedNodesEventArgs e) { var doc = new Document(parentId); var xml = doc.ToXDocument(false).Root; myIndexer.ReIndexNode(xml, IndexTypes.Content); } }
The event fires on reindexing, receives the correct document, but the fields aren't included in the index (checked it with Luke). When i understand the code of the ReIndexNode method correctly, the node i want to be indexed doesn't have to be in the index before.
I had a look at some of the unit tests of Examine. There I found the "Index_Move_Media_From_Non_Indexable_To_Indexable_ParentID" method. In there was this:
var currPath = (string)node.Attribute("path"); //should be : -1,2222,2112
Assert.AreEqual("-1,2222,2112", currPath);
//now mimic moving 2112 to 1116
node.SetAttributeValue("path", currPath.Replace("2222", "1116"));
node.SetAttributeValue("parentID", "1116");
//now reindex the node, this should first delete it and then WILL add it because of the parent id constraint
_indexer.ReIndexNode(node, IndexTypes.Media);
Now this is my code:
protected void Nlindexer_NodesIndexed(object sender, IndexedNodesEventArgs e)
{
var doc = new Document(parentId);
var node = doc.ToXml(new System.Xml.XmlDocument(), false).ToXElement();
var currPath = (string)node.Attribute("path");
node.SetAttributeValue("path", "-1,1067,1069,1069");
node.SetAttributeValue("parentID", "1069");
nlindexer.ReIndexNode(node, IndexTypes.Content);
}
I hoped this would work, but when I use Luke the node is still not indexed.
I think you may need to download examine source and stick a break point on BaseUmbracoIndexer.cs method ValidateDocument I suspect something a miss there not 100% though. The method is
/// <summary>
/// Ensures that the node being indexed is of a correct type and is a descendent of the parent id specified.
//check if this document is a descendent of the parent
if (IndexerData.ParentNodeId.HasValue && IndexerData.ParentNodeId.Value > 0)
if (!((string)node.Attribute("path")).Contains("," + IndexerData.ParentNodeId.Value.ToString() + ","))
return false;
return base.ValidateDocument(node);
}
I suspect if the home page id is 1069 you would probably have path like -1,1069 however the test is !((string)node.Attribute("path")).Contains("," + IndexerData.ParentNodeId.Value.ToString() + ",") you got that extra , so i suspect it will be false and there not be indexed?
Examine: include document of IndexParentId in index
Hi,
i set up two IndexSets for a multilingual website, each with a corresponding IndexParentId parameter.
Because the documents of these IDs correspond to the homepages of each language i need to include them in the index, but they aren't by default.
Like the Examine documentation states: "When this property is set, the indexing will only index documents that are children of this node."
How to solve this?
Thanks
Matthias
here is my follow-up. I tried to solve the problem with an event handler:
The event fires on reindexing, receives the correct document, but the fields aren't included in the index (checked it with Luke).
When i understand the code of the ReIndexNode method correctly, the node i want to be indexed doesn't have to be in the index before.
What am i doing wrong?
Did you ever got this working? I'm having the same problem.
Jeroen
I had a look at some of the unit tests of Examine. There I found the "Index_Move_Media_From_Non_Indexable_To_Indexable_ParentID" method. In there was this:
Now this is my code:
I hoped this would work, but when I use Luke the node is still not indexed.
Jeroen
Did anyone manage to work out a fix for this? I've got exactly the same problem in that I need to add the IndexParentId document to the given index.
Cheers,
B
Benjamin,
I think you may need to download examine source and stick a break point on BaseUmbracoIndexer.cs method ValidateDocument I suspect something a miss there not 100% though. The method is
/// <summary>
/// Ensures that the node being indexed is of a correct type and is a descendent of the parent id specified.
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
protected override bool ValidateDocument(XElement node)
{
//check if this document is a descendent of the parent
if (IndexerData.ParentNodeId.HasValue && IndexerData.ParentNodeId.Value > 0)
if (!((string)node.Attribute("path")).Contains("," + IndexerData.ParentNodeId.Value.ToString() + ","))
return false;
return base.ValidateDocument(node);
}
I suspect if the home page id is 1069 you would probably have path like -1,1069 however the test is !((string)node.Attribute("path")).Contains("," + IndexerData.ParentNodeId.Value.ToString() + ",") you got that extra , so i suspect it will be false and there not be indexed?
Regards
Ismail
is working on a reply...