Tuesday, April 21, 2009

Creating a Windows 7 Search Connector for SharePoint/MOSS 2007

After using search connectors in Windows 7 for several public Internet websites (see Image 1 of a search on Wikipedia) I wanted to add a connector to be able to search my corporate SharePoint 2007 sites.

Image 1
searchConnector1

After reviewing a few examples from Internet sites and with a little digging on on MSDN for the Enterprise Search Syntax Reference for MOSS/SharePoint (http://msdn.microsoft.com/en-us/library/aa637082.aspx) it turned out to be surprisingly easy. Search Connectors are denoted by an osdx file extension. Double clicking on the osdx file will create the search connector (located under your user profile; c:\users\<username>\searches) and create a shortcut in your Windows Explorer favorites sidebar.

Example 1
Example 1 below shows the code used to create a basic Search Connector that will include all sites within your SharePoint deployment. Within Example 1 the sections/variables that you will need to change are indicated below. To create a Search Connector for your SharePoint site copy the code from example 1 and paste it into notepad. Once you have the code in notepad change the three variables for your environment then save the file with an osdx extension (ex: “SharePoint Search (All).osdx”).

Example 1 Variables:
ShortName: The shortname is the display name of the Favorites folder that will appear in Windows Explorer. Make this value unique and make sure it represents the scope of the search.
Description: As the name states this is the description for the search. This one can be more verbose than the ShortName but to be honest it rarely shows up. This value is set as a file property on the Search Connector object (located  under “c:\users\<username>\searches”).
sharepoint_url: This one’s not a tag so you will have to look for it in the middle of the line (lines 5 & 6). Make sure this base URL is is set to the URL for your SharePoint deployment.

 Example 1: Code for default all sites (default search scope “All Sites”)

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="
http://a9.com/-/spec/opensearch/1.1/" xmlns:ms-ose="http://schemas.microsoft.com/opensearchext/2009/">
<ShortName>SharePoint (All Sites)</ShortName>
<Description>Search the SharePoint Server.</Description>
<Url type="application/rss+xml" template="
http://sharepoint_url/searchcenter/_layouts/srchrss.aspx?k={searchTerms}&amp;s=All%20Sites"/>
<Url type="text/html" template="
http://sharepoint_url/searchcenter/Pages/Results.aspx?k={searchTerms}&amp;s=All%20Sites"/>
<ms-ose:ResultsProcessing format="application/rss+xml">
<ms-ose:LinkIsFilePath>-1</ms-ose:LinkIsFilePath>
</ms-ose:ResultsProcessing>
</OpenSearchDescription>


Example 2
Example 2 adds on to what we have already learned about search connectors by making use of the default Search Scope for “People” within SharePoint. The Search Scopes are preconfigured filters/indexes defined within SharePoint. By referencing the “People” search scope then we can create a search connector that will search for an SharePoint user’s information.

Example 2 Variables:
In addition to the same variables as Example 1 we need to specify the SharePoint Search Scope. The Search Scope is defined by the variable “s” in the SharePoint url request string. This variable will need updated in both lines 5 & 6, the same as “sharepoint_url”.

Example 2: Code to search for People (default search scope “People”)

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="
http://a9.com/-/spec/opensearch/1.1/" xmlns:ms-ose="http://schemas.microsoft.com/opensearchext/2009/">
<ShortName>SharePoint (People Search)</ShortName>
<Description>Search for people on the SharePoint Server.</Description>
<Url type="application/rss+xml" template="
http://sharepoint_url/searchcenter/_layouts/srchrss.aspx?k={searchTerms}&amp;s=people"/>
<Url type="text/html" template="
http://sharepoint_url/searchcenter/Pages/Results.aspx?k={searchTerms}&amp;s=people"/>
<ms-ose:ResultsProcessing format="application/rss+xml">
<ms-ose:LinkIsFilePath>-1</ms-ose:LinkIsFilePath>
</ms-ose:ResultsProcessing>
</OpenSearchDescription>

Example 3
Example 3 continues the use of SharePoint search scopes. In this case we are utilizing multiple custom defined search scopes (http://office.microsoft.com/en-gb/sharepointserver/HA011648521033.aspx) to include on content from certain sites with SharePoint.

Example 3 Variables:
As with Example 2 the key difference from the original search connector is in defining the “s” variable for the custom Search Scope. In this case though we are specifying multiple search scopes in the “s” variable by separating them with a %2c (the ASCII html code for a comma). In example 2 the search connector definition looked like this “s=people”. Now we are searching across the custom search scopes “search_scope1”, “search_scope2”, and “search_scope3” by using the following definition “s=search_scope1%2csearch_scope2%2csearch_scope3”

Example 3: Code for custom search sites (default search scope)

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="
http://a9.com/-/spec/opensearch/1.1/" xmlns:ms-ose="http://schemas.microsoft.com/opensearchext/2009/">
<ShortName>SharePoint (search_scope)</ShortName>
<Description>Search the SharePoint Server (search_scope).</Description>
<Url type="application/rss+xml" template=
http://sharepoint_url/searchcenter/_layouts/srchrss.aspx?k={searchTerms}&amp;s=search_scope1%2csearch_scope2%2csearch_scope3/>
<Url type="text/html" template="
http://sharepoint_url/searchcenter/Pages/Results.aspx?k={searchTerms}&amp;s=search_scope"/>
<ms-ose:ResultsProcessing format="application/rss+xml">
<ms-ose:LinkIsFilePath>-1</ms-ose:LinkIsFilePath>
</ms-ose:ResultsProcessing>
</OpenSearchDescription>

Deleting Search Connectors
If/When you decide to delete a search connector that is no longer need make sure you delete the actual search connector itself that is located under c:\users\<username>\searches as well as the Windows Explorer favorites. There is no harm in only deleting the favorite except that when you go to reinstall the search connector you’ll notice te new favorite gets incremented up with “(#)'”.

No comments:

Post a Comment

Followers