Copied to clipboard

Flag this post as spam?

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


  • Matthias 87 posts 173 karma points
    Aug 25, 2011 @ 10:26
    Matthias
    0

    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

  • Matthias 87 posts 173 karma points
    Aug 26, 2011 @ 10:55
    Matthias
    0

    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 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 12, 2012 @ 13:21
    Jeroen Breuer
    0

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

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 12, 2012 @ 14:55
    Jeroen Breuer
    0

    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

  • Jamie Howarth 306 posts 773 karma points c-trib
    Jul 23, 2012 @ 09:20
    Jamie Howarth
    0

    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 4511 posts 10091 karma points MVP 2x admin c-trib
    Jul 23, 2012 @ 10:22
    Ismail Mayat
    0

    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 Sign in or register to post replies

Write your reply to:

Draft