In Part 1 I started discussing a solution provided to a client who requested advanced, context sensitive search using specific metadata fields from a BCS connection.
The final solution had multiple aspects including a Business Connectivity Services (BCS) connection to allow external data to be surfaced within SharePoint via an external content type and the following:
I. Create a search scope in Central Admin
II. Surface the search scope in the Site Collection
III. Create Managed Properties
IV. Create a custom Search page with customized Search Web Parts
Steps I. II. and III. were covered in Part 1 and the details of step IV. will be covered here.
IV. Create a custom Search page with customized Search Web Parts
With all of the preliminary steps covered in Part 1, we are now into the heart of designing context sensitive search.
This part of the process is broken out into a series of steps:
A. Create a new page
B. Add and configure an Advanced Search Web Part including customizing the XML.
C. Add and configure a Core Results Web Part
D. Add and configure a Search Web Part
Let’s dig in.
A. Create a new page. The first step is easy. Create a page that can be used to handle both the customized Advanced Search capability and the results that it nets. The specific steps can vary depending on whether you are working in a team or publishing site. I suggest using a page with Web Zones – either a Publishing Welcome Page with Web Zones or a Web Part Page. The steps below use a Web Part Page.
1. Navigate to the site in which you want to search.
2. Select Site Actions then More Options
3. Filter by Page on the left navigation menu then select Web Part Page and Create.
4. Give your page a name such as search.aspx, select a layout and a library in which to store the page.
B. Next we’ll Add and configure an Advanced Search Web Part.
1. If the page is not in edit mode, select Site Actions then Edit Page
2. Select Add a Web Part
3. Under Categories select Search, then under Web Parts select Advanced Search Box
4. Edit the Web Part as follows:
• Search box
• Search box section label
Change to read: Find residents that have… (Or, use another appropriate label.)
• Leave a checkmark next to at least one of the following:
• Show “All Words”
• Show “exact phrase”
• Show “any words”
• Show “none of these words”
• Click Apply button twice
• Scopes:
• Remove the Language picker
• Result Type label:
Enter Resident Results (Or, use another appropriate label.)
• Click Apply button (twice) – note that “Resident Results” won’t show up right away
• Properties
• Properties section label
Change to: Narrow your search… (Or, use another appropriate label.)
• Properties
Open dialogue box, replace xml with commented code from AdvSearchXML_Custom.txt
Important: AdvSearchXML_Custom.txt contains commented code. Pay special attention to the area commented as follows:
<!-- Add custom property definitions
Name = field name from database
Display Name = what users see in the drop down menu
-->
This is the area in which the field names must match the field names of the Managed Metadata properties created earlier (as discussed in Part 1 of this Blog).
For comparison, the original xml can be found in AdvSearchXML_OOB.txt
• Miscellaneous:
• Results URL
Change to: search.aspx (Or whatever the URL of your custom search page happens to be)
• Ok then Save & Close
The resulting Web Part will look something like this:
C. Add and configure a Core Results Web Part. The next piece of the puzzle is to configure the Core Results Web Part to filter the results that come in so that only the Residents scope and appropriate location are brought in.
1. If the search.aspx is not in edit mode, select Site Actions then Edit Page
2. Select Add a Web Part
3. Under Categories select Search, then under Web Parts select the Search Core Results Web Part
4. Edit the Web Part as follows:
• Location Properties
• Scope: Enter Residents
• Results Query Options
• Append Text To Query
Add a location as it’s found in the data source, for example “Coconut Grove”
• Appearance
Change title to Resident Search Core Results (or something else that is appropriate)
Search results will display something like this:
D. Add and configure Search Web Part. The Advanced Search Web Part and Core Search Results Web Part are surfaced in a custom page within a site to maintain search relevance and prevent users from the need to leave the site when searching for context relevant information. This is a unique page that is “buried” unless you find a way to surface it. While you could surface the page with a link, the logical way to surface the page is through a Search Web Part on the Home Page.
1. If the Home page is not in edit mode, select Site Actions then Edit Page
2. Select Add a Web Part
Note: If the Home page is not a Web Part page, first place your cursor in the location in which you want the Web Part to appear, then select Insert under the Editing Tools in the Ribbon. Select Web Part and continue with the remaining instructions.
3. Under Categories select Search, then under Web Parts select the Search Box then Add
4. Edit the Web Part as follows:
• Scopes Dropdown: Dropdown mode
Keep default: Do not show scopes dropdown, and default to target results page
• Miscellaneous:
• Check Display advanced search link
• Remove check next to Display user preferences link
• Advanced Search page URL
Enter: search.aspx (or the appropriate URL of your custom search page)
• Target search results page URL
Enter: search.aspx (or the appropriate URL of your custom search page)
• OK then Save & Close
So there you have it, custom, context sensitive search that keeps users in the site in which they are accustomed to working. And barely any code to worry about!