Copied to clipboard

Flag this post as spam?

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


  • Niklas Hjelm 104 posts 125 karma points
    Nov 16, 2011 @ 08:15
    Niklas Hjelm
    0

    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

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 16, 2011 @ 10:02
    Dirk De Grave
    0

    Hmm, not sure what you mean. Can you elaborate using an example please?

     

    Looking forward to your info.

    Cheers,

    /Dirk

  • Niklas Hjelm 104 posts 125 karma points
    Nov 16, 2011 @ 11:02
    Niklas Hjelm
    0

    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

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 16, 2011 @ 11:09
    Dirk De Grave
    0

    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

  • Niklas Hjelm 104 posts 125 karma points
    Nov 16, 2011 @ 11:19
    Niklas Hjelm
    0

    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

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 16, 2011 @ 11:22
    Dirk De Grave
    0

    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

     

  • Niklas Hjelm 104 posts 125 karma points
    Nov 16, 2011 @ 11:28
    Niklas Hjelm
    0

    Hi Dirk

    Thanks for the snippet. 

    The result is the same /media/3517/myimage.jpg8671300369157jpg

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 16, 2011 @ 11:37
    Dirk De Grave
    0

    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

  • Niklas Hjelm 104 posts 125 karma points
    Nov 16, 2011 @ 11:41
    Niklas Hjelm
    0

    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

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 16, 2011 @ 12:03
    Jeroen Breuer
    0

    DAMP has a few helper files for this. If you have the string you can do something like this:

    DAMP_Helper.GetImageUrl(xml);

    Jeroen

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 16, 2011 @ 12:06
    Dirk De Grave
    0

    @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

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 16, 2011 @ 12:15
    Jeroen Breuer
    0

    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

  • Niklas Hjelm 104 posts 125 karma points
    Nov 16, 2011 @ 12:23
    Niklas Hjelm
    0

    Hi Jeroen

    How do I go about submitting the patch to the source?

    / Niklas

  • Niklas Hjelm 104 posts 125 karma points
    Nov 16, 2011 @ 12:48
    Niklas Hjelm
    0

    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>

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 16, 2011 @ 12:54
    Jeroen Breuer
    0

    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

  • Niklas Hjelm 104 posts 125 karma points
    Nov 16, 2011 @ 13:11
    Niklas Hjelm
    0

    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
                     
            }

     

  • Niklas Hjelm 104 posts 125 karma points
    Nov 16, 2011 @ 13:57
    Niklas Hjelm
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft