Copied to clipboard

Flag this post as spam?

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


  • Elwyn 8 posts 28 karma points
    Feb 15, 2011 @ 21:23
    Elwyn
    0

    Umbraco Examine - restricting results to a particular node

    I have an index set up, which I can query with great results.

    However I have a section of my site, in which I would like to include a 'Search This Section' input, which would query the index but only return results from this node, or descendant nodes.

    I can create multiple separate indexs, and use the IndexParentId attribute of the IndexSet to restrict indexing to certain nodes, and build a sepaarte search control for this section of the site. This works, but it doesn't seem very elegant, and it is non trivial to add new searches to sections of the site.

    Ideally I would like to be able to specify a nodeId as a paramater to my search control, and have that restrict the results, say, when specifying the criteria.

    Is this possible? Or does lucene not 'know' about nodes by the time it has indexed everything?

  • kows 81 posts 151 karma points c-trib
    Feb 16, 2011 @ 08:39
    kows
    0

    i did this programatically:

      /// <summary>
            /// select under which node to search ; seperated nodeID's 
            /// </summary>
            public string Source { get; set; }

            private bool PathContainsSourceNodeId(string path)
            {
                foreach (string sNodeID in this.Source.Split(';'))
                {
                    if (path.Contains(sNodeID))
                    {
                        return true;
                    }
                }
                return false;
            }

    path being 

    SearchResult oSR;
    oSR.Fields["__Path"];
  • Elwyn 8 posts 28 karma points
    Mar 20, 2011 @ 21:21
    Elwyn
    0

    Thanks for your reply.

    If I understand this correctly, you are saying:

    -Complete a full search of the index

    -Itterate over each result checking for a condition (result path is within my allowed paths)

    -Show only matches.

     

    Is this the best way to tackle the issue?

    If my index is potentially large, is there a more effecient way to perform the search? (E.g. adding my requirements before the search is executed, perhaps as an Examine criteria/lucene paramater). Or has lucene lost the heirachical strucutre of the site in its index?

    It just seems less than ideal doing all the extra searching, for example if I am only wanting to search a node that has two children, performing the search on hundreds of nodes then doing a whole bunch of proccessing to get rid of the majority of the results...

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Mar 20, 2011 @ 23:06
    Aaron Powell
    0

    Have a look at the article I wrote on search collections with Examine - http://farmcode.org/post/2010/09/22/Searching-Multi-Node-Tree-Picker-data-(or-any-collection)-with-Examine.aspx

    This way you can do the filtering at search time.

  • Elwyn 8 posts 28 karma points
    Mar 22, 2011 @ 01:44
    Elwyn
    0

    Thanks kows and slace.

     

    I have implemented a solution similar to what kows posted, due to time pressure in this project and the fact I can reuse a great chunk of my code.

    I will revisit this and have a go at the solution posted by slace if I can convince the project managers it is worth the extra time :)

Please Sign in or register to post replies

Write your reply to:

Draft