Copied to clipboard

Flag this post as spam?

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


  • simon kerr 31 posts 85 karma points
    Oct 18, 2013 @ 17:55
    simon kerr
    0

    looping through multi node tree picker items in search

    I have a search set up to search art works. Each art work can have multiple views so I used the multi node tree picker so editors can choose relevant images. In my search however, when returning this field, it just concatenates all the nodeids together.

    I'm getting this appear when I output all the fields being brought back - artWorkImages : 10681070

    there are actually 2 images for this art work.

    Can anyone offer any suggestions? Maybe a different way of looping through results? I'm not sure. I could split it using substring but that doesn't seem like a good idea unless all umbraco id's are always going to be 4 numbers long.

    Any help greatly appreciated.


  • Funka! 398 posts 661 karma points
    Oct 19, 2013 @ 07:20
    Funka!
    0

    The MNTP has two ways of storing values, which you setup on the Data Type itself in the Developer section: XML or CSV.

    It looks like whatever code you're using to get these values from your document, you are probably storing these as XML but just not parsing it out correctly. So if all the XML tags are stripped or ignored or flatted, you would get all numbers jammed together like 10681070. One idea is for you to show us the code you're using to parse this and we might be able to help. But, another idea...

    If instead you configure your MNTP to store values as CSV, in my opinion this is sometimes much easier to deal with in code, since you just need to split by the comma, and your stored value would be 1068,1070.

    I hope this helps and hasn't completely missed the mark in your case. Good luck to you!

  • Funka! 398 posts 661 karma points
    Oct 19, 2013 @ 07:22
    Funka!
    0

    P.S., as soon as you hit 9000 items, your IDs will certainly start to be more than 4 digits long, so better to just figure this out the proper way!

  • Peter Jensen 32 posts 137 karma points
    Oct 19, 2013 @ 09:21
    Peter Jensen
    0

    Hey funka 

    I to use the approace as u do CSV files for mtnp are just lovely, cause u can do the .Replace(',',  " ") and u have and easy way to seacht for items in a category. 
    and Not least the overloaded method that takes and array of id and return IpublishedContent nodes. 

    but i am running into the same problem over and over again. if the user unpublish a node that is selected in the mtnp i get a nasty YSOD saying that it cant cast umbracoDynamicNull (something like that) to ipublishedcontent.

    Have u ever run into that ?  

  • Dallas 133 posts 405 karma points
    Oct 19, 2013 @ 15:31
    Dallas
    0

    @Peter, do you get the error when passing the mntp csv string to TypedContent overload?

    The issue is how do you update the MNTP to remove the document that was unpublished? The document could be selected in multiple pickers in multiple documents.

    One possible solution would be to use the uComponents Multipicker Relations datatype to create a relation between the selected document and the document with the picker. When the document is unpublished you can then easily find the pickers where the document is referenced in a picker and remove it from the picker property. ( remove the id from the csv list ) . This would probably require publishing the document with the picker but what need to consider that it could have unpublished changes.

    How many items are selected in the picker? it might be safer to loop over the csv items and create each IPublishedContent item one at a time.

  • simon kerr 31 posts 85 karma points
    Oct 21, 2013 @ 16:20
    simon kerr
    0

    hi, thanks for the reply. The code from within a normal template page is working fine, its when I'm returning results from a search.

    So, I'm doing the search, then getting the results and looping through them like this -

    @foreach (Examine.SearchResult result in searchResults)
    {
              @result.Fields["artWorkImages"]

    }

    this only returns the concatenated string. However, from the examine management in the developer section, when I do a search using my searcher, it also just returns the concatenated string.

     

     

     

     

     

  • Dallas 133 posts 405 karma points
    Oct 21, 2013 @ 18:36
    Dallas
    0

    @Simon

    It could be that the csv string is getting changed when examine indexes the content. See this blog post for details:

    http://shazwazza.com/post/Searching-Multi-Node-Tree-Picker-data-(or-any-collection)-with-Examine

    Dallas

Please Sign in or register to post replies

Write your reply to:

Draft