Crawling Publishing Images in SharePoint 2010

6 Jun

Publishing images cannot be used as crawled/metadata properties, you will only get empty results. The problem with this is that you may want to use images with search as a rollup for information using XSLT. There are a few tricks that you can do to get this data.

  1. Add another site column to the content type that is plain text and get the user to add the URL in. This can then be set up as another metadata property. This isn’t a very good option however as you don’t want the users having to fill in two columns for the same information.
  2. Add another site column to the content type that is plain text. You can then add an event receiver which grabs the URL from the publishing image and places it as plain text in the new site column. This can then be set up as a metadata property. This way isn’t a very clean way of getting the data as we need an additional field, and now some extra code that needs to run when we save the item just to get an image.
  3. Use page code behind to add a Meta tag in the header section of the page to hold the information we want to crawl. This option is quick and easy to implement if you have code behind.
  4. If code cannot be used you can add a Meta tag into the header section of the page layout itself. You can then read out the value of the publishing image into the meta tag content. This is the easiest solution as it requires three lines of code added into the page layout itself, so nothing compiled.
I am going to go through setting up step 4 as it is a really easy way of getting around this issue without any code, event receivers or additional fields.Assumptions:

  • You have a working Page Layout that you can edit
  • You have access the the Search Service Application
  • You have access to the search page to update the xslt

Adding the Meta Tag into the Header

  1. Edit your page layout in advanced mode in SharePoint designer, or open in visual studio
  2. View the page layouts aspx code and add the following head section below PlaceHolderPageTitle
    <asp:Content ID=”PageHead” ContentPlaceHolderID=”PlaceHolderAdditionalPageHead” runat=”server”> </asp:Content>
  3. Add the following meta tag in the new PlaceholderAdditionalPageHead. You will need to change the FieldName to the GUID of the publishing image field. If you don’t know the GUID, an easy way of getting this is to drag the field onto the page from the tool box under SharePoint controls > Content Fields.
    <meta name=’PageImageURL’ content='<SharePointWebControls:FieldValue  FieldName=”3de94b06-4120-41a5-b907-88773e493458” runat=”server” id=”ImageFieldUrl”/>’ id=”imageMeta” />
    Your code will look like:
  4. Save the changes.
  5. If you are using SharePoint designer go back out to the Page Layouts list and check in the new changes, publishing as a major version. You will then need to approve the changes to the Page Layout in the Master Page Gallery
  6. If you are using visual studio you will need to package the wsp and do an update
  7. Go to a page that is using the page layout and view the source. You will see a new meta tag with the image value in there

Setting up Search

  1. A crawl will have to be run before we can pick up the crawled property. Go into the search service application > Content Sources and run an incremental crawl.
  2. Once the crawl is complete go into MetaData Properties on the left hand menu under Queries and Results
  3. Click on Categories then Web. The meta tag we set up should be in here under PageImageUrl – the name we gave the meta tag itself
  4.  Now that we know the property has been crawled we can set up a metadata property which we can use with our XSLT.
  5. Go to Metadata Properties on the left hand menu and click on New Managed Property. Add the name you want the property to have, leave it as text, add a mapping to the crawled property “PageImageUrl” and allow it to be used in scopes.
  6. Run a full crawl to populate the new metadata property

Setting up the XSLT for the new property

  1. Go to the search page where the image needs to be shown and edit the Search Core Results web part.
  2. Edit the web part and add the following column to the Fetch Propertys
    <Column Name=”PageImageUrl”/>
  3. Edit the XSLT being used, either here in the web part by clicking XSL Editor, or in visual studio if you are deploying the XSLT
  4. Under the template where you want to display the image, add a variable
     <xsl:variable name=”pageimageurl” select=”testpageimageurl”/> 
    Then add in the code to display the image. We need to disable output escaping as the data we are grabbing is html, not just plain text. This will ensure the image gets displayed correctly
    <xsl:value-of select=”$pageimageurl” disable-output-escaping=”yes”/>
  5. Save the page.

You can now see the image that was saved in your results.


10 Responses to “Crawling Publishing Images in SharePoint 2010”

  1. Thunderer June 7, 2011 at 4:19 am #

    Great posting. Nice to see that we can fix the SharePoint crawler over complex columns without resorting to code-behind

  2. Prashanth December 13, 2011 at 3:26 am #

    Great post could you please let me know which page layout should be edited……………

    • edithzor December 13, 2011 at 3:42 am #

      Comments below (forgot to hit respond instead of comment)

  3. edithzor December 13, 2011 at 3:41 am #

    Hi Prashanth,

    You would add the code segments to the page layout which is associated to the content type that is being searched (one that has a publishing image field). A good example of this is news items, you may have a “News Page Layout” which is associated with your “News Content Type” and the news content type has a publishing image field.

    So if you wanted a search rollup of news items, and the “News Page Layout” has the metdata it needs for search, you can then use the image in your results.

    If you are using an OOTB page layout, you will have to find the page layout in SharePoint Designer and add the meta field to that one (for the relevant publishing image field).

    Hope this helps, let me know any more questions if you are still stuck.


  4. Prashanth December 13, 2011 at 4:05 am #

    Hi Amy,
    Thank you so much for the quick reply. Actually i have created the site using team site. I created custom list and then added site column Rollup Image to that custom List. May i know which page layout it is or let me know how can i find out that page layout.and how to get the sharepoint controls->content fields. I couldnt able to see that. Please give me a reply ASAP.

    • edithzor December 13, 2011 at 7:33 am #


      The Rollup Image field is a text field, not a publishing one, so you should be able to crawl this normally like any field. The above fix is for publishing images (which aren’t crawlable).

      If you want your Rollup Image to be crawled you will first have to add some content into a page into the image field and do a crawl (search doesn’t seem to pick up fields when they don’t have content, also make sure the page is published and approved), then you can follow the steps outlined in this post from “Setting up Search” onwards. Just use your rollup image column instead.

      Here’s some more information on setting up managed properties:

      Hope this helps 🙂


  5. Barbara Falchi June 14, 2012 at 11:19 am #

    You’re a genius, thanks so much for the trick .-)

    • edithzor June 14, 2012 at 11:23 am #

      great! im glad it helped 🙂

  6. Barbara Falchi June 14, 2012 at 3:29 pm #

    Reblogged this on NonsoloSharePoint – Baxy's Blog and commented:
    Interessante suggerimento su come indicizzare le publishing images in SharePoint 2010 (e di conseguenza utilizzarle per personalizzare i risultati del proprio search center)

  7. Garry Trinder (@garrytrinder) February 12, 2013 at 7:49 pm #

    Great post, thanks for sharing. 🙂

Leave a Reply

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

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: