x First time here? Check out the FAQ

Come work for Umbraco - The Umbraco HQ are hiring Project managers, .NET developers and DevOps people!

  • Avatar87posts172karma

    Examine: include document of IndexParentId in index

    Matthias started this topic August 25, 2011 @ 10:26

    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


  • Avatar87posts172karma
    Comment with ID: 87474
    Matthias posted this reply August 26, 2011 @ 10:55

    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);

                parentId = myIndexer.IndexerData.ParentNodeId.Value;
            }

            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.

    What am i doing wrong?


  • Jeroen Breuer posted this reply April 12, 2012 @ 01:21

    Did you ever got this working? I'm having the same problem.

    Jeroen


  • Jeroen Breuer posted this reply April 12, 2012 @ 02:55

    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.

    Jeroen


  • Benjamin Howarth posted this reply July 23, 2012 @ 09:20

    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


  • Ismail Mayat posted this reply July 23, 2012 @ 10:22

    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

     

     

     


Please login or Sign up To post replies