Does anyone know how I can show and image from a search result from Examine. Let's say I have a media property on a page and the page gets a hit, and I want to show that image.
I'm trying to show an image in a searchresult. Right now I have the following code
@if(node.Fields.Keys.Contains("mainImage")) { var image = node.Fields["mainImage"]; @Html.Raw(image)
}
Which works fine except that I get to much.
/media/3517/myimage.jpg8671300369157jpg
For some reason I get numbers plus jpg without the dot in the end. Don't know why and either I have to try to get the correct media url or use a regex, and I'm having trouble with both :)
Might be close to a solution... Guess your image variable is an xml fragment which you output using @Html.Raw() -> guess that's where it's going wrong... I think you have to convert the value returned from node.Fields[""] into a XDocument and use a linq2xml statement to get the url of the image only.
Anyway, for testing purposes, just output the value of image in a textbox (and see whether that is just a xml fragment)?
Not sure what you mean by textbox but when I tried to use @(image) I get the same result. Could you give me an example of what to use. Programing is not my dayjob :)
Hmm, further investigation... is that a upload datatype or a media picker on the document? Have you tried Luke before? If you use Luke, you can inspect what data has been written to your index? I'd suggest to have a look at the index files and find out how the image data is stored in the index...
@Jeroen, as I understand from the OP, seems that no *xml* is returned from the Examine index... guess OP probably has to look into getting the xml in the index rather than the current string
It seems the xml data is returned with a .ToString() method which removes all of the xml and you only get /media/3517/myimage.jpg8671300369157jpg back. I fixed it for LinqToUmbraco by submitting a patch to the source. Perhaps the same needs to be done for examine.
Hmm, not sure how examine works I think. If I do this I get the url for the image correct since it does a search for umbracoFile and not mainImage but this is not very good since it only does a search for the the inside "umbracofile". My index gets to small :) Isn't there a better way to do this?
Looks like I've found a solution where I only do a search where there is an image. The image therefore exicts and I do not need to use contains. Thanks for your help.
Examine and Image
Does anyone know how I can show and image from a search result from Examine. Let's say I have a media property on a page and the page gets a hit, and I want to show that image.
Thanks / Niklas
Hmm, not sure what you mean. Can you elaborate using an example please?
Looking forward to your info.
Cheers,
/Dirk
Hi Dirk!
I'm trying to show an image in a searchresult. Right now I have the following code
@if(node.Fields.Keys.Contains("mainImage"))
{
var image = node.Fields["mainImage"];
@Html.Raw(image)
}
Which works fine except that I get to much.
/media/3517/myimage.jpg8671300369157jpg
For some reason I get numbers plus jpg without the dot in the end. Don't know why and either I have to try to get the correct media url or use a regex, and I'm having trouble with both :)
Cheers / Niklas
Might be close to a solution... Guess your image variable is an xml fragment which you output using @Html.Raw() -> guess that's where it's going wrong... I think you have to convert the value returned from node.Fields[""] into a XDocument and use a linq2xml statement to get the url of the image only.
Anyway, for testing purposes, just output the value of image in a textbox (and see whether that is just a xml fragment)?
Cheers,
/Dirk
Not sure what you mean by textbox but when I tried to use @(image) I get the same result. Could you give me an example of what to use. Programing is not my dayjob :)
/ Niklas
Ok, a small code snippet:
@if(node.Fields.Keys.Contains("mainImage")) {
var image = node.Fields["mainImage"];
<textarea>@image</textarea>
}
And find out what is in the textarea field...
Cheers,
/Dirk
Hi Dirk
Thanks for the snippet.
The result is the same /media/3517/myimage.jpg8671300369157jpg
Hmm, further investigation... is that a upload datatype or a media picker on the document? Have you tried Luke before? If you use Luke, you can inspect what data has been written to your index? I'd suggest to have a look at the index files and find out how the image data is stored in the index...
Cheers,
/Dirk
Hi Dirk
It's a DAMP datatype for a single image. Is there anyway to transform the string to remove everything after .jpg?
Thanks / Niklas
DAMP has a few helper files for this. If you have the string you can do something like this:
DAMP_Helper.GetImageUrl(xml);
Jeroen
@Jeroen, as I understand from the OP, seems that no *xml* is returned from the Examine index... guess OP probably has to look into getting the xml in the index rather than the current string
Cheers,
/Dirk
Hmm I've also had this problem with LinqToUmbraco a while back:
http://our.umbraco.org/forum/core/41-feedback/12211-LINQ-to-Umbraco-reading-XML-inside-a-property
http://umbraco.codeplex.com/workitem/28731
It seems the xml data is returned with a .ToString() method which removes all of the xml and you only get /media/3517/myimage.jpg8671300369157jpg back. I fixed it for LinqToUmbraco by submitting a patch to the source. Perhaps the same needs to be done for examine.
Jeroen
Hi Jeroen
How do I go about submitting the patch to the source?
/ Niklas
Found out where the numbers came from. It takes everything under mainImage. Is there a way I can get only the "umbracoFile" part?
Thanks for all your help!
<mainImage>
<DAMP fullMedia="">
<mediaItem>
<Image id="1228" version="ab79a86b-0c2e-460a-bdb3-8e80258a3f8d" parentID="1062" level="2" writerID="0" nodeType="1032" template="0" sortOrder="62" createDate="2011-11-08T21:58:57" updateDate="2011-11-08T21:58:56" nodeName="My image" urlName="myurl" writerName="Niklas Hjelm" nodeTypeAlias="Image" path="-1,1062,1228">
<umbracoFile>/media/5520/myimage.jpg</umbracoFile>
<umbracoWidth>1300</umbracoWidth>
<umbracoHeight>867</umbracoHeight>
<umbracoBytes>460372</umbracoBytes>
<umbracoExtension>jpg</umbracoExtension>
</Image>
</mediaItem>
</DAMP>
</mainImage>
You can do that with the helper I just showed on page 1, but that only works if you get this xml back from examine and not a stripped version.
Jeroen
Hmm, not sure how examine works I think. If I do this I get the url for the image correct since it does a search for umbracoFile and not mainImage but this is not very good since it only does a search for the the inside "umbracofile". My index gets to small :) Isn't there a better way to do this?
@if(node.Fields.Keys.Contains("umbracoFile"))
{
var image = node.Fields["umbracoFile"];
@image
}
Looks like I've found a solution where I only do a search where there is an image. The image therefore exicts and I do not need to use contains. Thanks for your help.
/ Niklas
is working on a reply...