How to: Create an OpenSearch Provider for SharePoint

Posted Monday, May 17, 2010 5:07 PM by CoreyRoth

A while back, Kevin Williams pointed out to me that certain web sites could be searched in Google Chrome using the syntax <ur> query in the address bar.  For example, once I have been to youtube.com, I can later type in youtube to initiate a search query.

ChromeOpenSearchYouTube

Pressing tab, give you a spot to enter your query or you can just type a space and put in your keyword.

ChromeOpenSearchYouTube2

As someone that does a lot of work with SharePoint Enterprise Search, this got me thinking.  I want my SharePoint site to show up in my browser too.  I did some research and discovered this is part of OpenSearch and that I can achieve the same result with any OpenSearch compatible search engine (which SharePoint is), so I knew this would be relatively easy to research.  I figured this kind of thing might already be included in SharePoint 2010 (and maybe it is and I just haven’t found it), but from what I can tell it’s not.  If anything, you can use this technique in SharePoint 2007 as well.  If this file is auto generated somehow, I would love to hear about it.

To get started, you must first create an XML file which describes where to point search queries on your web server.  The filename does not matter (search.xml in my case).  The syntax is pretty simple, but there are a couple of things to watch out for.  I started with Microsoft’s description of how to create a file on MSDN.  However, it appears there is an issue in the documentation (or maybe something changed in a different version).  The issue I saw is that on the URL element, it says you an attribute called format.  I could not get this to work so I looked at working examples on site and discovered they had the attribute listed at type.  The other issue I ran into in this file is apparently the ShortName element cannot have capital letters in it.  Here is what my entire file looks like for my server called sp2010

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">

  <ShortName>sp2010</ShortName>

  <Description>sp2010</Description>

  <Url

    type="text/html"

    method="get"

    template="http://sp2010/search/results.aspx?k={searchTerms}" />

  <Url

    type="application/rss+xml"

    method="get"

    template="http://sp2010/_layouts/srchrss.aspx?k={searchTerms}&amp;start={startIndex}&amp;cnt={count}" />

  <Image height="16" width="16" type="image/vnd.microsoft.icon">http://sp2010/_layouts/images/favicon.ico</Image>

</OpenSearchDescription>

The ShortName element specifies the keyword to type into Chrome to prompt you to do a search (i.e.: youtube.com up above, sp2010 in our case).  You need to already have a search center created.  In my case I have a site called Search and I will point to a results page in there called results.aspx.  You will change this according to your environment.  For browser based search results, we use a type of text/html.   We use the keyword URL syntax here so the browser passes in what you searched for as the {searchTerms} token to the k query string parameter.   You will notice I have a second Url element present.  This is here in case you want to use this same while to do Windows 7 federated search.  I’ll talk briefly about that in the end, but it uses the path to the RSS feed of your search results.  You can also include a custom image icon with the search results as well along with many other things.  Read the MSDN article for more information on what you can put in this file.

The next thing we need to do is put this XML file somewhere on the SharePoint server.  You can just open SharePoint designer and drag it to the root of the server or put it in a document library somewhere.  It doesn’t matter as long as you know the URL to it.  The next thing we have to do is put a link tag in your master page file specifying where this XML file is.  You should normally deploy master pages via solution package and feature, but for today’s purposes, I just opened SharePoint Designer and customized v4.master (gasp!).  Remember v4.master is the new default master page for sites running on v4.  Add the following line somewhere in the head tag and change the URL to your XML file.

<link rel="search" type="application/opensearchdescription+xml" href="/XmlLibrary/search.xml" title="SP2010" />

Remember to check the file in when you are done.  One thing to point out about SharePoint 2010 is that it won’t serve up some file type directly to the browser (it forces a download).  I think this may cause issues, so at the suggestion of @danluciano, I changed the browser file handling of my Web Application in central admin (Central Admin –> Web Applications –> General Settings).  It’s set to Strict by default and I changed it to Permissive.  You don’t need to worry about this in SharePoint 2007.  Honestly, it may work in SharePoint 2010 without changing this but when I was running into issues getting things working earlier this seemed to be a possible issue.  If you try it without, let me know. :-)

WebApplicationGeneralSettingsFileHandling

At this point, if you did everything right, you should be able to use your new keyword in Chrome after visiting your SharePoint site.  Here is what mine looks like after type in sp2010.

ChromeOpenSearchSharePoint

 

Hitting enter I get my usual search results page.

OpenSearchResults

I think this is pretty cool.  You should be able to use this in other browsers as well such as IE8, but I really like how Chrome handles it.  Now I mentioned Windows 7 federated search.  You can take the file you created above, save it to your desktop as .odcx file extension and install it. What makes this possible is the second URL element we specified using the application/rss+xml type.

OpenSearchInstallODCX

 

You will see the following prompt.

OpenSearchConnectorPrompt

When you open Windows Explorer, it will show your SharePoint site in the list of Searches.  It also adds it to your favorites.

Windows7FederatedSearchList

Clicking on the SP2010 search connector here allows us to search the SharePoint site directly.  You will be prompted for authentication if necessary.  Executing the same search query above looks like this.

Windows7FederatedSearch

Clicking on any of the links takes you directly to SharePoint.  Remember you can implement this now with SharePoint 2010 or SharePoint 2007.  It’s definitely cool and another great way to get data out of SharePoint.

Comments

# Twitter Trackbacks for How to: Create a OpenSearch Provider for SharePoint - Corey Roth - DotNetMafia.com - Tip of the Day [dotnetmafia.com] on Topsy.com

Pingback from  Twitter Trackbacks for                 How to: Create a OpenSearch Provider for SharePoint - Corey Roth - DotNetMafia.com - Tip of the Day         [dotnetmafia.com]        on Topsy.com

# re: How to: Create an OpenSearch Provider for SharePoint

Tuesday, March 15, 2011 4:39 AM by Shamshad Ali

Hello,

I want to add sortKeys and few other parameters, How to I do this?

I have posted similar query here: social.msdn.microsoft.com/.../457c98de-504c-4263-b977-3e5d3ae42900

Shamshad Ali.

# re: How to: Create an OpenSearch Provider for SharePoint

Tuesday, June 21, 2011 5:57 AM by josetellan

Hi, is it possible to create a search connector for sharepoint 2010 to point google....in spanish???..., i mean, all of the search connectors are in english but my customer wants them in spanish....is there a way to achieve  this or is absolutly imposible??

thankssss

# re: How to: Create an OpenSearch Provider for SharePoint

Friday, July 8, 2011 4:29 PM by CoreyRoth

I would think it's possible.  You just have to find the right URL to use with google that can provide those results in an OpenSearch format.

Leave a Comment

(required)
(required)
(optional)
(required)