Sunday, December 8, 2013

Build a Custom Search Results Page with Facets in SharePoint 2010

Introduction

This article shows you how to create a custom site collection search results page, with search facets, in five easy steps.  You will be shown how to do this using nothing more than the standard web front end tools (page edit mode) and the out-of-the-box web parts that come with SharePoint Server 2010.  Site Collection Administrator privileges will be needed to actually point site collection search to the new search results page, but the rest can be done with no more than standard Contributor permissions.  Creating a custom search results page is remarkably easy, and this article shows you how.

There are a few assumptions to keep in mind, as you work through this article.  The first is that the SharePoint Server Publishing Infrastructure feature has been activated for the target site collection. Second, it assumes that you have added content to your site collection, such as Office documents.  Third, it assumes that  Search has been successfully configured and that content has been indexed.  Lastly, it assumes that a Search center has not been configured and that site collection search results are still being presented in the default search results page.  One more thing: in developing this article, I performed the testing against a special corpus of content that I created that has been seeded with keywords designed to return known results.

Step 1: Add a new page
  1. Navigate to the top site of the site collection.
  2. From the Site Actions dropdown, select More Options.
  3. Select Page, from the Filter By group, at left, and then select Web Part Page.
  4. Click Create.
  5. Enter a name for the new page.  For this article, MyCustomSearchResults was used.
  6. Select the Layout Template.  For this article, the Header, Left Column, Body template was used.
  7. Then select the document library where you want to page to be stored.  For this article, the Site Pages library was used.  You could also use the Site Collection Documents library.
  8. Click Create.  The new web part page is created, and your browser is navigated to the page in edit mode.
  9. On the Page ribbon, click the Stop Editing button.  The page is refreshed, and now appears in normal mode.
Step 2: Add basic search results capability
  1. In the Body web part zone, click Add a Web Part.  A new section appears on the web page, from which you can select web parts.
  2. In the Categories section, scroll down and select Search; then, in the Web Parts section, use the arrow links to browse the search web parts for Search Core Results, and then select this web part.
  3. Click the Add button.  The page is refreshed to show the new web part in the Body web part zone.
  4. On the Page ribbon, click the Stop Editing button.  The page is refreshed, and now appears in normal mode.
Step 3: Configure the Site Collection Search to use the custom page
  1. From the Site Actions dropdown, select Site Settings.
  2. In the Site Collection Administration group, click Search Settings.  The browser is navigated to the Search Settings page.
  3. In the Site Collection Search Results Page field, enter the path and filename to your new custom search results page.  For this article, the path and filename would be: /SitePages/MyCustomSearchresults.aspx. Leave all other settings at their default values.
  4. Click OK.  Now to test the results against the test content.
  5. The first test will use the keyword document010, which should return just three results: one each of Word, PowerPoint and Excel documents.
    Performing the search returns the expected results. 
    So far so good.
  6. The second test will use the keyword Global010, which should return 30 results: 10 each of Word, PowerPoint and Excel documents.  Performing the search does not return the expected results.
  7.  
Step 4: Add Paging Capability
  1. With your browser still connected to the new custom search results page, on the ribbon, select the Page tab, and then click the Edit Page button.  The page is refreshed to display it in edit mode.
  2. In the Body web part zone, click Add a Web Part.  A new section appears on the web page, from which you can select web parts.
  3. In the Categories section, scroll down and select Search; then, in the Web Parts section, use the arrow links to browse the search web parts for Search Paging, and then select this web part.
  4. Click the Add button.  The page is refreshed to show the new web part in the Body web part zone.
  5. Optional: by default, the new web part appears above the existing one.  However, you can easily move it below, by simple drag-and-dropping methods.  For this article, the Search Paging web part is moved to below the Search Core Results web part.
  6. On the Page ribbon, click the Stop Editing button.  The page is refreshed, and now appears in normal mode.  Now to test the results against the test content.
  7. The test will again use the keyword Global010, which should return 30 results: 10 each of Word, PowerPoint and Excel documents.  Performing the search returns a list of 10 results, and paging tools now appear.
  8. The next step is to implement search facets.
Step 5: Add search facets
  1. With your browser still connected to the new custom search results page, on the ribbon, select the Page tab, and then click the Edit Page button.  The page is refreshed to display it in edit mode.
  2. In the Left Column web part zone, click Add a Web Part.  A new section appears on the web page, from which you can select web parts.
  3. In the Categories section, scroll down and select Search; then, in the Web Parts section, use the arrow links to browse the search web parts for Refinement Panel, and then select this web part.
  4. Click the Add button.  The page is refreshed to show the new web part in the Left Column web part zone.
  5. While were at it, let's add one more useful search web part: the Search Statistics web part, which displays the number of results returned and how many you are currently viewing (given search paging).  Add the web part using the same method as previously. 
    After you finish, you'll see two web parts displayed at left.
  6. On the Page ribbon, click the Stop Editing button.  The page is refreshed, and now appears in normal mode.  Now to test.
  7. The test will again use the keyword Global010, which should return 30 results: 10 each of Word, PowerPoint and Excel documents.  Performing the search returns a list of 10 results, as expected. 
    The search facets display the default facets.  Note that the Search Statistics web part discretely displays the number of currently viewed search results. 
Summary

This article has shown you how to implement a custom site collection search results page in just five easy steps, and all without writing any code, nor even using SharePoint Designer for that matter.  For additional details on the topics discussed in this article, consult the references below.

References

No comments: