Copied to clipboard

Flag this post as spam?

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


  • Neil Tootell 73 posts 118 karma points
    Jan 07, 2011 @ 17:33
    Neil Tootell
    0

    Examine fluentAPI - using an array of keywords

    Hi all,

    I'm getting pretty reasonable with examine now but have hit a brick wall with creating a list of IExamineValue's inside a GroupedOr IBooleanOperation.

    The code below very nearly works, but it only searches against the first item in the iListPracticeNones array. Not sure if what I am trying to do is possible but any advice would be much appreciated. "practices" is a node that may have sub-practice children.

    //Check for children
                    Node umbPractice = new Node(int.Parse(practices));
                    Nodes umbChildPractices = umbPractice.Children;
                    //If a practice group, then add all children in a "grouped or"
                    if (umbChildPractices.Count > 0)
                    {
                        ArrayList ChildPracticesFiltered = new ArrayList();
                        //add parent item in to complete filter
                        ChildPracticesFiltered.Add(practices);
                        foreach (Node n in umbChildPractices)
                        {
                            if (n.NodeTypeAlias == "practice")
                            {
                                ChildPracticesFiltered.Add(n.Id.ToString());
                            }
                        }
                        string[] strPracticeList = (String[])ChildPracticesFiltered.ToArray(typeof(string));
                        IExamineValue[] iListPracticeNodes = new IExamineValue[strPracticeList.Length];
                        for (i = 0; i < strPracticeList.Length; i++)
                        {
                            iListPracticeNodes[i] = strPracticeList[i].MultipleCharacterWildcard();
                        }
                        filter.And().GroupedOr(
                            new string[] 
                            { 
                                "practices"
                            },
                                iListPracticeNodes
                            );
                    }

  • Neil Tootell 73 posts 118 karma points
    Jan 11, 2011 @ 11:09
    Neil Tootell
    0

    Right - I think I've sorted it.

    The GroupedOr can be overloaded with a string rather than iExamineValue. It seems to work correctly if I make sure there are equal numbers of parameters in both inputs to the functions. "practices" is the parent node ID for a dropdown search filter that may have children.

    So in my case, if I have 4 items in my iListPracticeNodes array, then I need "practices" times 4 in the field array. I've done it with a count and it works.

    Here's my code in case anybody is interested...

     

    if (practices != "")
                {
                    //Check for children
                    Node umbPractice = new Node(int.Parse(practices));
                    Nodes umbChildPractices = umbPractice.Children;
                    //If a practice group, then add all children in a "grouped or"
                    if (umbChildPractices.Count > 0)
                    {
                        ArrayList ChildPracticesFiltered = new ArrayList();
                        //add parent item in to complete filter
                        ChildPracticesFiltered.Add(practices);
                        foreach (Node n in umbChildPractices)
                        {
                            if (n.NodeTypeAlias == "practice")
                            {
                                ChildPracticesFiltered.Add(n.Id.ToString());
                            }
                        }
                        string[] strPracticeList = (String[])ChildPracticesFiltered.ToArray(typeof(string));
                        string[] strPadOutSearchFields = new string[strPracticeList.Length];
                        for (i = 0; i < strPracticeList.Length; i++)
                        {
                            //pad out search fields to match the number of search practices - in this case we want to add "practices" field
                            //the number of times a practice field has been found.
                            strPadOutSearchFields[i] = "practices";
                        }
                        filter.And().GroupedOr(strPadOutSearchFields, strPracticeList);
                    }
                    else
                    {
                        //Add parent practice only
                        filter.And().Field("practices", practices.MultipleCharacterWildcard());
                    }
                }

     

    This gives a nice "grouped or" for adding a dropdown selection with children to an Examine query. 

Please Sign in or register to post replies

Write your reply to:

Draft