Previously I’d looked at having a search that shows thumbnails of images in SharePoint. I modified the results page to do this – but the results themselves would still show non-Picture items (e.g. documents, pages, etc.). In this post, I’ll configure up a new Search Scope for images only.
Search Scopes are found through the Shared Service Provider (SSP) Search settings page:
If we View the Scopes, we get a list of the scopes and which Web Apps they’re available on:
Click on New Scope to create a new scope (obviously!) At this stage you only give it a name; rules are defined later:
Hit OK and create the scope. The Scopes list view now prompts you to ‘Add Rules’ to the scope:
Click on Add Rules to do so:
Rules can be based on a number of things – Content Source, Web Address, or Property. Properties are just Managed Properties that are configured to allow themselves to be used in scopes. You can add to those Managed Properties and make more available in this list.
For our scope, I’m using the ContentClass property. I know from my previous article the value that this is for Picture items, and I’m going to make this rule Required – I want all items in this scope to have the content class of STS_ListItem_PictureLibrary (that just trips off the tongue).
Anyway, once those fields have been filled in, press OK. Go back to the Search Settings page and go to the Scope section:
The scopes periodically update themselves; this section will tell you when the next update is. If you’re impatient, you can kick off an update immediately.
So, once the scope is created and updated, we want to use it. First, we have to configure it in our Site Collection. This does mean that different site collections can share (or not) different scopes. Go to the Site Collection Settings:
Click on Search Scopes:
This shows us the search scopes available in the site collection and the ‘Display Groups’ those scopes are in. ‘Display Groups’ controls where the scopes are available. For example, the above screenshot shows the scopes available for the small search box and the advanced search.
We’ll add our scope to the small search box. Click on Search Dropdown.
Now we can edit the display group. Check the ‘Display’ checkbox next to our Images scope. Hit OK.
Next we need to go to a page which uses the small search box and shows the scope drop down list. Your system might not always show that list. I configured my search page to display this drop down list (by editing the Search Box web part), and ran a search for ‘snake’ using the default ‘All sites’ scope:
This returned me document and images about snakes. I then used the drop down box to select my ‘Image’ scope, and ran the search again:
Hurray! Search results about snakes that only include Picture items in Picture Libraries. Obviously, you may want some sort of more complex Scope Rules to accept pictures from other sources.
Be careful about using the FileExtension managed property though (as suggested here) as the FileExtension property for images comes through in the results XML as ASPX?ID=x
. I don’t get why, but I don’t seem to be able to get a url such as http://server/documents/myimage.jpg
– instead they all come through as http://server/documents/Forms/DispForm.aspx?ID=x
. I’ll investigate that sometime; this doesn’t seem to be a factor of the XSL though.
Anyway, using Picture Libraries is good if you can get away with it.
Biggest problem with this solution is down to how Microsoft handles images on publishing pages. For whatever reason, the system generated image (or publishingimages) library is a DOCUMENT library, and the contents are not in the scope you set up. This is very frustrating, as fileextension is the only reliable way to ID images, but as you pointed out the actual image filename is not exposed.
Fred
Well, I didn’t know that – that’s interesting – and a really dumb choice, as you say.
[…] 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. […]
“I configured my search page to display this drop down list (by editing the Search Box web part)” — how did you do this?
– Go to the search results page.
– Choose ‘Edit’ from the ‘Site Actions’ menu
– On the Search Box Web Part use it’s menu to select ‘Modify Web Part’
– In the Web part toolbox change the settings for the web part. I forget what it’s called, but there is one about whether a scopes drop down should be shown.
Thanks for this. Just set it up for my own internal marketing team. It looks fab, even if I say so myself.
Any idea how I can add a download picture or save picture button?
Not sure, off the top of my head – normally images are just opened if you click on them in a browser.I don’t know if there is a browser setting that might control that behaviour – but that’d affect more than just your search page. Otherwise, there may be a way of doing it through JavaScript.
Interesting question, if I get time I’ll maybe take a look at that.