Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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:
<img src="<%# ((Examine.SearchResult)Container.DataItem).Fields["mainImage"] %>" alt=""/></a>
<%# ((Examine.SearchResult)Container.DataItem).Fields["nodeName"] %></a></h4>
<p><b>Tags:</b><span class="tags"> <%# ((Examine.SearchResult)Container.DataItem).Fields["tags"] %></span></p>
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!
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?
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.
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.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted