Sunday, February 24, 2013

SharePoint 2013: Image Preview in Search Results - Part III

This is the third and final post of the image preview series. Here is Part I and Part II.

I left off having a consistent search result from images both stored in picture libraries as well as a regular document libraries. The results show a preview on the page but the hover doesn't have a larger view. This is an easy fix.

UPDATE: Get the source files here

Showing a Preview Image in the Image Search Result Hover Panel


Problem
Hovering over the image search results does not show a larger preview image:

 
Solution
 

Modify the Item_Picture_HoverPanel.html file and add the following code right before the first if statement:
 
 <div class="ms-srch-hover-imageContainer">
       <img id="_#= ctx.CurrentItem.csr_id =#_" src="_#= $urlHtmlEncode(ctx.CurrentItem.Path) =#_" onload="this.style.display='block';" />
  </div>
 

Save the file and refresh the search results. A larger image shows in the hover now:


If you do not have a Search Center site collection and only see .js files, here is the modification to the Item_Picture_HoverPanel.js:

,'                <div id="', $htmlEncode(id + HP.ids.body) ,'" class="ms-srch-hover-body">'
,''
,'                        <div class="ms-srch-hover-imageContainer">'
,'                            <img id="', ctx.CurrentItem.csr_id ,'" src="', $urlHtmlEncode(ctx.CurrentItem.Path) ,'" onload="this.style.display=\'block\';" />'
,'                        </div>'
,'                '
);
                    if(!Srch.U.n(ctx.CurrentItem.PictureURL)){



 

10 comments:

  1. Replies
    1. I deleted your comment content by accident. Did you add a Comments column to your Picture/Image Library? Did you add it from existing site columns or create a new one? You'll either need to look up the Managed Property (which should be Comments but please verify) or map the new column to the Comments managed property. Add Comments to the ManagedProperties tag in the display template and then you can reference ctx.CurrentItem.Comments to display the comments.

      Delete
    2. hi Steve how can display search result images like videos in enterprise search

      Delete
    3. You mean having an Images results page?

      Delete
    4. In Enterprise Search videos navigation display videos in horizontal with hover similarly we want to display images in horizontal with hover panel

      Delete
    5. we added a comments in Image library its a existing site column

      Delete
    6. The template used in the Video results page is some sort of special system template. I'll dig in some more on that. The compact horizontal video template can be used in Everything but doesn't show hover. I am going to generate one for images. I'll try to incorporate the hover. I'll also post something about the comments.

      Delete
    7. Here are the Image Horizontal Display steps: http://stevemannspath.blogspot.com/2013/05/sharepoint-2013-search-creating-image.html

      Delete
  2. Hi Steve

    Awesome tutorial. I just created custom display templates and applied those instead of editing the SP ones.

    Many thanks and regards,

    Lee

    ReplyDelete
    Replies
    1. Yah! That is what you are supposed to do.

      Delete