Copied to clipboard

Flag this post as spam?

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


  • mcgwest 23 posts 55 karma points
    Aug 19, 2009 @ 17:41
    mcgwest
    0

    Search Nodes by Property

    I need to be able to search for publish nodes based on a property. For example, if I have an Employee document type with the property FirstName, how can I search for nodes based on the FirstName property using the API?

    Thanks.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 19, 2009 @ 17:53
    Thomas Höhler
    0

    iterating through the umbraco.presentation.nodefactory...

    You also can use the simple search 4 umbraco.

    if you have questions just contact me via th |at| thoehler |dot| com

    Thomas

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 19, 2009 @ 20:15
    Dirk De Grave
    103

    Either iterating (but don't think that's a good idea performance-wise or you could use the available umbraco.library functions (and which are available from both .net code and from xslt

     

    /// <summary>
            /// Queries the umbraco Xml cache with the specified Xpath query
            /// </summary>
            /// <param name="xpathQuery">The XPath query</param>
            /// <returns>Returns nodes matching the xpath query as a XpathNodeIterator</returns>
            public static XPathNodeIterator GetXmlNodeByXPath(string xpathQuery)
            {
                XPathNavigator xp = content.Instance.XmlContent.CreateNavigator();
    
                return xp.Select(xpathQuery);
            }

     

    In your case, xpath expression would be something along the lines of:

     

    //node [string(./data [@alias = 'FirstName']) = 'Employee']

     

    Hope this helps.

     

    Regards,

    /Dirk

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 19, 2009 @ 20:17
    Dirk De Grave
    1

    Oh, and another option is to use the search functionality available through Lucene.net (which is also available OOB)

    If you need some samples (it's bit more complicated than using the library functions), shoot me an email at dirk at netaddicts dot be

     

    Btw: Thomas' simple search 4 umbraco is also a perfect candidate, i'm merely summing up the possibilities.

     

    Cheers,

    /Dirk

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 19, 2009 @ 21:48
    Thomas Höhler
    0

    Lucene is by default not indexing the properties if a node. So you have to implement BeforeIndexing Handlers (I did this before implementing SS4U) and an own search interface to Lucene. IMHO not a simple way.

    And SS4U is really fast (much faster than Lucene in our tests for a site with 1000 nodes), cause the object model is in memory as the xml is. Also you can set startnodes and define which doctypes and properties to search.

    But as Dirk says: there are several options. It depends on things like experience with xpath/xslt or .Net and the site size and the structure and so on...

    Also: if you don't need to access via api you can also take xsltsearch from doug, etc.

    Hope that I did not confuse you to much ;-)

    Thomas

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 19, 2009 @ 22:03
    Dirk De Grave
    0

    oh, thanks for refreshing my mind, i have used those event handlers, that is why i was thinking it's standard functionality.! it's not!

     

    cheers,

    /Dirk

     

  • mcgwest 23 posts 55 karma points
    Aug 20, 2009 @ 01:45
    mcgwest
    0

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft