Friday, February 22, 2013

SharePoint 2013: Image Preview in Search Results - Part II

This is the second post on previewing images in SharePoint search results. The first post is here.

In the first post I demonstrated a way to display image previews in search results and resolved two problems. But what about the images in a Picture Libary? I didn't see them appear in search results as pictures until I added the file types. Shouldn't there be special results for Picture types?

UPDATE: Get the source files here


Previewing of Images Stored In Picture Libraries

Problem #1: Images in Picture Libraries Returned as Files or List Items
After going through the steps in Part I , even images stored in Picture Libraries are returned as files themselves. The hover works fine but you should be able to take advantage of the image result type.

Solution to Problem #1: Copy and Configure the Image Result Type

In your Search Center site collection select Site settings from the settings menu:

Under Site Collection Administration, click on Search Result Types:


Scroll down and find Image. Use the drop-down menu and select Copy:


On the Add Result Type page, select Picture Item udner What should these results look like?


Click Save:
Run a search for an item in a Picture Library:



 
There is a preview image right in the results! That's great but that didn't happen in image results from other types of libraries - onto Problem #2.
 
Problem #2: Image Search Results Not Consistent
Now the results from a Picture Library and non-Picture Library look different. It is not consistent for the user:

Solution to Problem #2: Modify the Display Template for the Result.
This time you need to edit the Item_Picture.html file.

Simply add an else statement to the if in the middle of the code:

 else {
           ctx.CurrentItem.csr_PreviewImage = ctx.CurrentItem.Path;
      }


(If you only see .js files, the .js code to  modify is at the bottom of this post)

Save the file and run a search again:

 


Now all images that are returned have a preview image in the results!!!!

But now the hover is the Picture Library List item hover, not the one I modified in the first post. So in the next and last post of this series I modify that hover to include a larger preview!



If you are not running search in a Search Center Site Collection and/or you only see .js files in your Search Display Templates, here is the resultant .js code to paste over after the render header in Item_Picture.js:

    if(!Srch.U.n(ctx.CurrentItem.PictureThumbnailURL) && !ctx.CurrentItem.IsContainer) {
     ctx.CurrentItem.csr_PathLength = Srch.U.pathTruncationLengthWithPreview;
                    ctx.CurrentItem.csr_PreviewImage = ctx.CurrentItem.PictureThumbnailURL;
       }
      else {
           ctx.CurrentItem.csr_PreviewImage = ctx.CurrentItem.Path;
      }



 

12 comments:

  1. Steve, any idea on how to only make the advanced page return images based on result types?

    ReplyDelete
    Replies
    1. Here's what I am thinking:

      1. Don't make any Search modifications at the Site Collection level.
      2. Create a sub-site in your search center
      3. Make Search modifications on the sub-site at the Site level (under Site Administration not Site Collection Administration)
      4. Create an Advanced Search results page in the sub-site
      5. Configure your advanced search to point to the Advanced Search results page in the sub-site.

      I'll look into this as I just came up with that in my head.

      -=Steve

      Delete
  2. Thank you so much! That did the trick, you saved me more endless hours of searching for a fix.






    Image Processing Company in Chennai

    ReplyDelete
  3. Hello Steve,

    According to screen shots in your post, using OR keyword you have searched for 2 images. Do we have to create any query rules for creating such behavior as i am unable to achieve it OOB.

    ReplyDelete
  4. The original post (part 1) was the first thing I tried, however, you don't need to do that. You just need to change the display template used as explained in this post.

    ReplyDelete
  5. Someone posted a comment and I accidentally clicked on the Delete link instead of publish. Here is the comment:

    Hi, this solution works great for me when I search for Images stored in SharePoint. For images form a fileshare I just can't get a preview - anyone else with the same problem? I already checked all the managed metadata I'm getting back from fileshare images with the great search query tool but I didn't find a solution.

    ReplyDelete
  6. Hi
    How about Sharepoint Online from Office 365? I couln't find something to add jpg, png, gif als file types.

    Best regards
    Christoph

    ReplyDelete
    Replies
    1. True. There are certain admin aspects of Search that are not exposed in SPO. I'll check out the search behavior for those types.

      Delete
  7. Hi, I have a suggestion. You can use Image Rendition to increase a perfomance of a page:

    ctx.CurrentItem.csr_PreviewImage = ctx.CurrentItem.Path + "?RenditionID=1";

    It is better in cases when original image size is not small. You also can create your own rendition, or make double check to show rendition or oroginal size but with sharepoint css styling.

    ReplyDelete
  8. Thanks Steve, for your prompt response. The reason I ask is that in spite of having continuous crawl enabled, adding the JPG file to the Search results and re-indexing the library, we still have the issue of only the item properties coming back in the search results, instead of the actual link to the image.
    We did what you described in the article, in our DEV environment and it works well. The only diff is that we ran a full crawl there. Doing a full crawl in PROD is a bit of a challenge, as we have Continuous crawl in Production, and we are using just that one content source for all the URLS. Do you know if creating a separate content source and trying a full crawl of just the URL that we need, would interfere with the continuous crawl set up, (Because the URL is also included in the first Content source that has the continuous crawl and we want to leave that untouched). Really appreciate your help, thanks!

    ReplyDelete
    Replies
    1. the search service won't allow you to create a content source that contains URLs from the main content source. Try the Reindex option at the list/library level as well as the site level.

      Delete

Matched Content