Showing Thumbnails in Search

One of my colleagues was asking about building a search which would show thumbnails for images, and whether that was possible. I decided to try a 5 minute prototype, so I took a copy of the results.aspx page in my Search Center, and started hacking…

I have a Picture library with some images in it (they’re pinched from Flickr, so sorry for the copyright thing to their respective owners – but they’re lovely looking test data). You might notice that the images in the pictures Library are already thumbnailed:

Picture Library with Sample pictures

Firstly, I took a look at all the xml I was getting back from the search results. (You can add to that.)

Search results XML

Great! So I’m getting the thumbnail for the picture through in the search results, and I can also identify what pictures are by the ContentClass. Nice one!

Normal Results pages XSL

The first thing I noticed on opening up the XSL for the normal results page was that there is a section about showing a thumbnail. Normal search results don’t show a thumbnail though – so what gives?

Well, there are a few conditions before it’ll show the thumbnails – the ContentClass of the result (which is okay), the presence of a thumbnail URL, and the variable $IsThisListScope being true. I’m not sure what the $IsThisListScope variable is for, but I decided to delete it from the condition. As the other parts are met the results should show thumbnails for items which have them (i.e. Pictures).

Redesigned XSL

And if I perform a search for, say, balloons, then I get some results with thumbnails:

Results page showing Thumbnails.

Now, it’s worth noting, this page will still show non-pictures results – just my results didn’t have any. The next step would be to create a scope to only include images.

Advertisement
Showing Thumbnails in Search

3 thoughts on “Showing Thumbnails in Search

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.