in

Dot Net Mafia

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for Ionic, SharePoint, and Office 365.

Exposing Enterprise Search Results using RSS

I am working on a talk about how to get data out of Enterprise Search for #SPSOzarks.  One of my clients particularly has asked me a lot on this subject.  Sure you can get to the data by using the API with KeywordQuery, FullTextSqlQuery, or the Web Service.  However, sometimes the simplest solution is best.  If you don’t need any custom managed properties, just need a keyword query, and just want some XML with search results in it, why not use the built in RSS feed.  It in fact is quite easy to use.  Consider the following search results.

SearchResults

The RSS button you see on the Search Results page works must like the CoreResultsWebPart does in that it uses the query string syntax to execute Keyword queries.  If you look at the link that the RSS button provides, it makes a call to the application page at _layouts/srchrss.aspx and it makes use of the same k and s parameters that the CoreResultsWebPart does plus a few extra ones.  The k parameter is for the user’s keyword query (in this case, we searched for the word Company).  The s parameter specifies the scope.  You can also specify a start parameter to start the results on a specific record.  There is also a u parameter (which I don’t know what it does) and a source parameter to specify a referring URL.  So to construct an RSS feed for the above results, it would look something like the following:

//_layouts/srchrss.aspx?k=company&s=All%20Sites">http://<servername>/<SearchCenterUrl>/_layouts/srchrss.aspx?k=company&s=All%20Sites

It would yield XML that looks like this.

<?xml version="1.0" encoding="utf-8"?>

<?xml-stylesheet type="text/xsl" href="http://moss-server/SearchDemo/_layouts/RssXslt.aspx" version="1.0"?>

<rss version="2.0" xmlns:srrt="http://schemas.microsoft.com/WebParts/v3/srchrss/runtime">

  <channel>

    <title>Search Results: company</title>

    <link />

    <description>Search RSS feed for Microsoft Office SharePoint Server 2007</description>

    <language>en-US</language>

    <lastBuildDate>Tue, 23 Jun 2009 19:05:09 GMT</lastBuildDate>

    <generator>Microsoft Office SharePoint Server 2007 RSS Generator</generator>

    <ttl>60</ttl>

    <image>

      <title>Search Results: company</title>

      <url>http://moss-server/SearchDemo/_layouts/images/homepage.gif</url>

      <link />

    </image>

    <item>

      <title>Company Marketing</title>

      <link>http://moss-server/SearchLibrary1/Company Presentation 5.pptx</link>

      <description>

        <![CDATA[<div style="margin-top:5px"><link rel="stylesheet" type="text/css" href="http://moss-server/_layouts/1033/styles/portal.css" /><span class="srch-Icon"><a href="http://moss-server/SearchLibrary1/Company Presentation 5.pptx" title="Company Marketing"><img src="http://moss-server/_layouts/images/icpptx.gif" alt="Result of type: document" border="0" /></a></span><span class="psrch-Description"><b>Company</b> Marketing 

    …

   Why our <b>company</b> </span><p class="srch-Metadata"><span class="srch-URL"><a href="http://moss-server/SearchLibrary1/Company Presentation 5.pptx" title="Company Marketing">http://moss-server/SearchLibrary1/Company Presentation 5.pptx</a>

        -

        45KB

          </span></p></div>]]>

      </description>

      <author>Windows User</author>

      <pubDate>6/22/2009</pubDate>

    </item>

    </channel>

</rss>

I cut out most of the item elements from the XML for brevity but you get the point.  You get a link the results along with a title and description.  At this point, you can easily consume these results with an RSS client or maybe use LINQ to XML to parse them.  Interested in what the document looks like when there are no matching search results? 

<?xml version="1.0" encoding="utf-8"?>

<?xml-stylesheet type="text/xsl" href="http://moss-server/SearchDemo/_layouts/RssXslt.aspx" version="1.0"?>

<rss version="2.0" xmlns:srrt="http://schemas.microsoft.com/WebParts/v3/srchrss/runtime">

  <channel>

    <title>Search Results: noresultskeyword</title>

    <link />

    <description>Search RSS feed for Microsoft Office SharePoint Server 2007: No results found</description>

    <language>en-US</language>

    <lastBuildDate>Tue, 23 Jun 2009 19:39:57 GMT</lastBuildDate>

    <generator>Microsoft Office SharePoint Server 2007 RSS Generator</generator>

    <ttl>60</ttl>

    <image>

      <title>Search Results: noresultskeyword</title>

      <url>http://moss-server/SearchDemo/_layouts/images/homepage.gif</url>

      <link />

    </image>

  </channel>

</rss>

You just get an RSS document back with no items and the description tells you that no results were found.   As you can see executing queries with RSS is pretty simple, so if you need a quick solution, this may be the way to go.

Comments

 

Joost Kinkel said:

Hi Corey, do you know if it 's possible to configure a custom managed property and get that property to appear in the RSS XML-file? Or is RSS too rigid for that? thanks!

August 2, 2010 8:21 AM
 

CoreyRoth said:

I haven't been able to figure out a way to get it to show up in the RSS results.  I think it may be possible but I need to look into it more.

August 2, 2010 9:26 AM
 

SharePoint 2010 Enterprise Search KeywordQuery Class, KeywordQuery Class said:

Pingback from  SharePoint 2010 Enterprise Search KeywordQuery Class, KeywordQuery Class

March 23, 2011 4:14 AM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2018 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems