Copied to clipboard

Flag this post as spam?

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


  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Feb 24, 2011 @ 08:52
    Sebastiaan Janssen
    0

    Should .Contains be working at the moment?

    I've tried variations of this, but I keep getting errors, so I'm just wondering if Contains is built in:

    @Model.Articles("bodyText.Contains({@0})", "ipsum")

    I did find an interesting blog post with a sample implementation, might be good to work off of.

  • Gareth Evans 142 posts 334 karma points c-trib
    Feb 24, 2011 @ 09:18
    Gareth Evans
    0

    No, no support for that yet.

    Do you want to return all articles where the bodyText property contains ipsum?

    You could try and do it with where, but I haven't tested it.

    This is a fairly advanced use-case of where:

    Dictionary<string,object> values = new Dictionary<string,object>();
    values.Add("keyword", "ipsum");
    var searchResults = Model.Children.Where("bodyText.Contains(keyword)", values);
    @foreach(var item in searchResults)
    {
    @item.Name;
    }

    No promises!
    If this doesn't work, we might need a few more IEnumerable implementations for searching/filtering

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Feb 24, 2011 @ 09:40
    Sebastiaan Janssen
    0

    I was trying to do something a little more advanced, I'm looking for all articles that have (in a multinode picker) one of the following Id's in them: 5182,5183 or 5184.

    Just wanted to present a simplified version here, so I tried above code but I get the same error I've been getting before: 

    No applicable method 'Contains' exists in type 'Func`2'


  • Gareth Evans 142 posts 334 karma points c-trib
    Feb 24, 2011 @ 09:53
    Gareth Evans
    0

    Okay, this is probably a use-case for a more advanced selection method.

    If you can somehow iterate over the IDs you want, you can call Model.NodeById(...) and pass that in. That will give you each node in turn.
    If they're media items, use Model.MediaById(...)

    If the use-case is selecting multiple nodes by ID number, then I'd probably implement this as overloads on those two methods.
    If it's searching/filtering complex like the ipsum sample below, I'm not sure what the best signature would be - open to suggestions.

    What will be happening with the Contains in the where is at the time it evaluates that, it doesn't know that it's a Dynamic - it's a path I haven't upgraded for DynamicNode yet

    I'd be interested in some suggestions about how the code should read in the .cshtml file

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Feb 24, 2011 @ 11:01
    Sebastiaan Janssen
    2

    Nah, I am really trying to compare two arrays (which I know is pretty hard to do in Linq anyway), here's something I threw together in uQuery real quickly:

        var picker = Model.KeywordsPicker.ToString().Split(',');
        var foundNodes = new List();
        foreach (var p in picker)
        {
            var currentP = p;
            var nodes = uQuery.GetRootNode().GetDescendantNodes().Where(x => x.GetPropertyAsString("keywordsPicker").Split(',').Any(k => k == currentP));
            foreach (var n in nodes.Where(n => foundNodes.Contains(n) == false))
            {
                foundNodes.Add(n);
            }
        }

    With regards to more of a "normal" Contains method, I think the one in my opening post look quite right. But while you're building that, you might run into problems with empty values though, because you can't type them properly.. 

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 24, 2011 @ 11:58
    Jonas Eriksson
    2

    It's hard to see support for all possible future uses of lambdas put into DynamicNode. Wouldn't it be nice to add some uQuery/uQl IEnumerable<Node>'s node extensions? And functions to convert back and forth from DynamicNodeList <-> IEnumerable<Node> ?

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 24, 2011 @ 12:56
    Hendy Racher
    1

    Hi Sebastiaan,

    It sounds like the Relations API might be benficial to you here ?

    Rather than string chop a CSV, or parse XML fragments for each node, a single DB hit to get all Nodes related to picked NodeIDs should be much quicker.

    There's a datatype called MultiPicker Relations in uComponents that can wire up multipickers so that they automatically create the relations.

    HTH,

    Hendy

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Feb 24, 2011 @ 14:21
    Sebastiaan Janssen
    0

    Thanks Hendy, I really should look into the relations API one day. It's too late for this project, but doing string splits has been giving me enough headaches before! Thanks for the tip!

  • Eran Meir 401 posts 543 karma points
    Apr 11, 2011 @ 16:31
    Eran Meir
    0

    i've just tried the following code like Garath suggested 

     

     Dictionary<string,object> values = new Dictionary<string,object>();
            values.Add("filter",filter);
            foreach (var item in @Model.Descendants("BlogPost").Where("tags.Contains(filter)", values))
            { 
                <li>@item.Name</li>
            }

    but i get the following error

    No applicable method 'Contains' exists in type 'String'

     

  • Eran Meir 401 posts 543 karma points
    Apr 11, 2011 @ 16:41
    Eran Meir
    0

    never mind, its ok :)
    seems like i forgot checking the filter for null

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Oct 07, 2012 @ 18:59
    Shannon Deminick
    0

    Have got some unit tests working for this kind of thing in 4.10 and have created a task for it:

    http://issues.umbraco.org/issue/U4-995

    Pretty much all methods and extension methods should work dynamically now.

Please Sign in or register to post replies

Write your reply to:

Draft