Recently, while working at requirements for a Government client I was tasked with finding a way to create rss feeds for site wide searches. Here, I've decided to share this solution with the wider community.

Being able to subscribe to search results with RSS is useful to sites such as twitter.com where there is a large amount of content or frequently updated information. When a user may only be interested in a small sub-set of all this information, it may be useful to offer them an RSS feed. RSS feeds help to make it more convenient for people to stay up to date with changes to content on a website.
To accomplish this, I've used Views 2 to create a new search page for performing a site wide search. In addition to views, the following modules also had to be enabled: PHP input filter, Search, and Views UI. In this example, I've used the devel generate module to generate a large set of nodes on which to test my search.
Step 1. Build the page view

The page view will replace the core search module's search block and page. Begin by creating a new page view. As fields, add "Node: Title" and "Node: Teaser". As filters, use "Node: Published" and the important one, "Search: Search Terms". This search filter hooks into the drupal core search and must be exposed to allow users to enter search terms. I've set the path as 'search-site'. It is also advisable to turn the pager on(It comes in handy later).
Add "Search: Score" under sort criteria and ensure it is set to descending.
Note that search results are only indexed when CRON is run. If you are not seeing any results, please run cron.
Since we want to direct users to our new search page, the core search block should be disabled.

Step 2. Build the rss view
Next, we add a feed display to the view. Most of the settings will be the same as those of the page view, however, in addition, we must also set "RSS Feed" as the Style and "Node" as the Row Style(under basic settings). I've set this path as 'search-rss'.

Step 3. The PHP used to tie them together.
So at this point we have two pages we can look at, YOURDOMAIN/search-site and YOURDOMAIN/search-rss. Both of their content changes based on text which is passed in through the URL where "keys" is set as some text after the ? in the URL.

To put these two pages together we must create a link from the 'search-site' page to the 'search-rss' page so that variables that are being passed in through the URL are preserved. To do this I've added the following PHP to the header of the views page that was set up.

<?php
$view = views_get_current_view();
$rss_url = 'search-rss?keys='.$view->exposed_input['keys'];
$rss_icon = theme_feed_icon( $rss_url , $view->exposed_input['keys']);
echo "<div>";
echo "<p>Current search yields ".$view->total_rows ." results. " ."<br/>Save your search and get periodic updates ".$rss_icon ;
echo '<span><a href="http://www.whatisrss.com"> [What is this?]</a></span></p>';
echo "</div>";
?>
$view = views_get_current_view();
$rss_url = 'search-rss?keys='.$view->exposed_input['keys'];
$rss_icon = theme_feed_icon( $rss_url , $view->exposed_input['keys']);
echo "<div>";
echo "<p>Current search yields ".$view->total_rows ." results. " ."<br/>Save your search and get periodic updates ".$rss_icon ;
echo '<span><a href="http://www.whatisrss.com"> [What is this?]</a></span></p>';
echo "</div>";
?>
The code simply grabs the current view's exposed input ("keys") and creates a link to the rss page. theme_feed_icon() creates that nice orange RSS symbol for me.
The variable $view->total_rows is only available when pagination is enabled.
The result is a new search page for the site that will also give you an rss feed based on the terms that were searched for.
An export of the view is here.
Here are two more screenshots:


| Attachment | Size |
|---|---|
| site_search_view.txt | 5.53 KB |

