Copied to clipboard

Flag this post as spam?

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


  • Adam Southorn 11 posts 31 karma points
    Nov 12, 2012 @ 19:06
    Adam Southorn
    0

    Examine search results

    Hi all,

    I've been searching the forum and Google for a while but can't seem to find an answer for a hopefully simple question...

    Using umbraco.tv I've set up a search using Examine for my website. Everything is working well and the search results are showing up fine, however I can't figure out how to add a thumbnail.

    The thumbnail is a media picker in umbraco with the alias "mainImage", and my ItemTemplate for the user control is below:

    <ItemTemplate>
    <li>
        <a href="<%#((Examine.SearchResult)Container.DataItem).FullUrl()%>">
        <img src="<%# ((Examine.SearchResult)Container.DataItem).Fields["mainImage"] %>" alt=""/></a>
        <h4><a href="<%#((Examine.SearchResult)Container.DataItem).FullUrl()%>">
        <%# ((Examine.SearchResult)Container.DataItem).Fields["nodeName"] %></a></h4>
        <p><b>Tags:</b><span class="tags"> <%# ((Examine.SearchResult)Container.DataItem).Fields["tags"] %></span></p>
    </li>
    </ItemTemplate>

    As you can see, it's showing the URL, name and the related tags successfully, but my custom mainImage field is causing an error: "The given key was not present in the dictionary."

    I've since tried with other custom fields, including text strings, media pickers etc, but no luck.

    I'm hoping it's just due to my lack of Examine experience and I've missed something really simple, but I have looked everywhere and can't find a similar question or thread.

    Thanks in advance for any help you have!

    Adam.

  • Ismail Mayat 4511 posts 10056 karma points MVP 2x admin c-trib
    Nov 13, 2012 @ 10:18
    Ismail Mayat
    0

    Adam,

    Can you use luke (http://luke.codeplex.com/) and take a peak in the index what do you see when you do search. Can you see that field? 

    Regards

    Ismail

  • Adam Southorn 11 posts 31 karma points
    Nov 13, 2012 @ 10:52
    Adam Southorn
    0

    Hi Ismail,

    Thanks, I couldn't find the field, turns out there was a spelling error where I was adding the field to my index. D'oh, complete fail on my part.

    The only problem after that was that it would only return the image ID. I ended up writing this ugly bit of code to get the image to show up:

     

    <img src="<%# umbraco.MediaExtensions.GetImageUrl(new umbraco.cms.businesslogic.media.Media(int.Parse(((Examine.SearchResult)Container.DataItem).Fields["mainImage"])))%>" alt=""/></a>

    Looks like there should be an easier way but nothing else was working for me! Feel free to contribute if anyone has a much shorter version of the above.

    Thanks again,

    Adam.

     

  • Ismail Mayat 4511 posts 10056 karma points MVP 2x admin c-trib
    Nov 13, 2012 @ 11:18
    Ismail Mayat
    0

    Adam,

    To cut down the amount of code you can make use of GatheringNodeData event and during indexing get the mainImage value get the media item then the actual url and inject the url into a new examine field say called imainImageUrl.  That way in your repeater you can then have 

    <img src="<%# ((Examine.SearchResult)Container.DataItem).Fields["mainImageUrl"] %>" alt=""/>

    See here about GatheringNodeData event

     

    You have a bit of work todo but its done during indexing time thus when you get your search results it will be more performant because you are doing the lookup for the url from the index. So one getfield call will be quicker than getting field from examine then getting media item.

    Regards

    Ismail 

Please Sign in or register to post replies

Write your reply to:

Draft