Scott on Writing

Musings on technical writing...

Searching Your Blog Got a Whole Lot Easier

If you check out the ScottOnWriting.NET homepage you'll now find that in the upper-left hand corner there's a spiffy “Search” box.  Go ahead, type a query in there... you'll be redirected to http://scottonwriting.net/Search.aspx?s=ScottOnWriting.NET&count=10&first=1&query=query, which will show you the results of your search.

The new search page - which you, too, can add to your site in a matter of minutes - is possible in large part thanks to Microsoft's new MSN Search.  Today Microsoft unveiled their new “built from the ground up” search and one of the cool features it that the search results can be returned as RSS.  (To try it out, go to the MSN Search page and enter a query; at the bottom of the Web page you'll find that little, friendly orange RSS button.)  Once I found this, I realized adding search to ScottOnWriting.NET would be a cinch if MSN Search let me search for pages on a particular domain.  Thankfully, you can search by a specific site by simply adding site:siteName syntax in the search query.

Creating a search engine for a local site, then, is as easy as having a page that requests the remote RSS file based on the query entered by a user, and displaying the resulting RSS in the page.  With my free RssFeed control doing exactly this is a no-brainer, requiring just two lines of code.  Therefore, the code and markup for the search page for ScottOnWriting.NET basically looks like:

Source Code
// Build up the request URL for the RSS data
string requestUrl = string.Format("
http://beta.search.msn.com/results.aspx?q={0}+site%3a{1}&format=rss&first={2}&count={3}", searchQuery, “http://ScottOnWriting.NET/“, startIndex, resultsPerPage);

// Bind the results to the RssFeed control
searchResults.DataSource = requestUrl;
searchResults.DataBind();

Markup
<skm:rssfeed width="80%" id="searchResults" runat="server" Font-Names="Verdana"
  Font-Size="Medium" CellPadding="5" ShowHeader="False" GridLines="None">

 <ItemTemplate>
  <span class="title"><a href='<%# DataBinder.Eval(Container.DataItem, "Link") %>'><%# DataBinder.Eval(Container.DataItem, "Title") %></a></span><br />
  <span class="desc"><%# HighlightSearchTerm(DataBinder.Eval(Container.DataItem, "Description").ToString()) %></span><br />
  <span class="url"><%# DataBinder.Eval(Container.DataItem, "Link") %></span>
 </ItemTemplate>
  
</skm:rssfeed>

Some example results can be seen here.

This is pretty cool, but there are some gotchas. 

  1. The RSS feed doesn't provide any information if there's more results.  There may be 15 results for the query DataGrid, but the RSS feed, by default, will only return the first 10.  There's no way of knowing for sure if there are more results unless you grab another RSS feed, this time asking for records starting at 11.  What complicates things is that if there are exactly 10 records, getting the RSS feed starting at 11 won't return nothing; rather it will re-return the first 10 records.  Ick.  My current solution is to just display a Next button if there are 10 records on the page... it's a hack, since it won't really do what is expected for queries that return a multiple of 10 records, but it's good enough.
  2. I don't know how legal all this is.  If you look at the RSS feed's <copyright> tag it says:

    Copyright © 2005 Microsoft. All rights reserved. These XML results may not be used, reproduced or transmitted in any manner or for any purpose other than rendering MSN Search results within an RSS aggregator for your personal, non-commercial use. Any other use of these results requires express written permission from Microsoft Corporation. By accessing this web page or using these results in any manner whatsoever, you agree to be bound by the foregoing restrictions.

    I doubt MS is going to care too much if I use these results for my dinky little blog, but clearly they'd care if I was a company that used this approach to provide search on my Web site in lieu of buying Index Server or Google's searching server, or whatever.

Of course, MSN Search is not the first search engine to provide a programmatic means for accessing their results.  Google offers the Google API, a set of Web services that can be used to run queries on Google.  In fact, I've written an article on 4Guys on how to create a search engine with the Google API: Searching Google Using the Google Web Service.  (And I will likely write up an article on using the MSN Search technique...)  The downside of using the Google API is that users are limited to 1,000 queries per day and creating a page to work with the API takes a bit more heavy lifting than just bringing back RSS data and displaying it (although not much more).

A future blog entry, or 4Guys article, will delve into the MSN Search techniques I used to add search to ScottOnWriting.NET, but don't let that stop you from adding this feature to your site today.  Armed with RssFeed you could do it without further information in a matter of minutes.

posted on Tuesday, February 01, 2005 9:54 AM

Feedback

# re: MSN Search Launches 2/1/2005 11:10 AM msnsearch's WebLog

# re: Searching Your Blog Got a Whole Lot Easier 2/1/2005 11:23 AM James Shaw

Very neat! I did see this in an earlier msnsearch blog though, so be warned (my highlight):

"We are planning to keep the feeds up during the experiment, but will not if they are abused. Use them from your RSS readers,

***
but please don't recreate our search engine with them.
***

But don’t get me wrong – this is a service we want to provide and make great."

# re: Searching Your Blog Got a Whole Lot Easier 2/1/2005 12:16 PM Milan Negovan

Psssst, Scott, why not just create a full-text catalog, kick off an incremental population of the catalog, add tables to it, then columns. Enable change tracking and you're all set.

It's that easy! :)

# re: Searching Your Blog Got a Whole Lot Easier 2/1/2005 12:23 PM Scott Mitchell

Milan, your comments are valid for me, but what about those folks who are on a blog site (like weblogs.asp.net) where they don't have access to the database? They could create this page on their personal site that could be used to search their blog indirectly...

Also, who knows what algorithm MS (or Google) uses to index a page. I wouldn't be surprised if it's "better" than full text indexing. That is, when I type in a query, their engine might do more things with it, more similar permutations, and the index they have might be intelligent to ignore certain redundant parts of the page and whatnot that full text indexing won't......

# Lets implement MSN Search 2/1/2005 9:56 PM Vinod Kumar's Blog

# soderlind.no - Search your WordPress blog using MSN Search and aggrss 2/2/2005 2:33 AM Pingback/TrackBack

soderlind.no - Search your WordPress blog using MSN Search and aggrss

# re: Searching Your Blog Got a Whole Lot Easier 2/2/2005 7:47 AM Ryan Farley

Funny, I did the exact same thing a few weeks ago, even down to using your excellent RssFeed control.

See: http://ryanfarley.com/blog/archive/2005/01/12/1410.aspx

My search page here:
http://ryanfarley.com/Search.aspx

Using your RssFeed control really made it a breeze to throw together in literally minutes. Thanks!

BTW, as far as the "more records" thing, you can specify a number larger than 10 if you want to using the "count" parameter in the Query String like this to get the first 100 results:

http://beta.search.msn.com/results.aspx?q=Ryan+Farley&format=rss&count=100

Granted not ideal, and I'm sure you played with that as well, but better to use a Next button and page back the results (I could't find any better way to do it than what you came up with either.

-Ryan

# re: Searching Your Blog Got a Whole Lot Easier 2/3/2005 8:19 AM Yazid

where did you get this control

<skm:rssfeed ... />

Could it be any control

# re: Searching Your Blog Got a Whole Lot Easier 2/3/2005 8:28 AM Scott Mitchell

RssFeed is a control I created, Yazid. You can learn more about it and download the complete source code over at:
http://scottonwriting.net/sowBlog/RssFeed.htm

hth

# re: Searching Your Blog Got a Whole Lot Easier 5/31/2005 1:10 PM artudigna

Did you ever figure out a way to get a total count of the results, rather than 10 at a time?

# Blog Search 7/3/2005 7:49 PM Javier G. Lozano

# Blog Search 7/4/2005 2:42 PM Javier G. Lozano

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

Add To Your Reader

My Links

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<May 2008>
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Comment Stats

DayTotal% of Total
Sunday 1866.8%
Monday 37913.9%
Tuesday 45316.7%
Wednesday 50418.5%
Thursday 53519.7%
Friday 49418.2%
Saturday 1666.1%
Total 2717100.0%

Hour1Total% of Total
12:00 AM 652.4%
1:00 AM 682.5%
2:00 AM 622.3%
3:00 AM 742.7%
4:00 AM 572.1%
5:00 AM 1033.8%
6:00 AM 1084.0%
7:00 AM 1585.8%
8:00 AM 1716.3%
9:00 AM 1475.4%
10:00 AM 1716.3%
11:00 AM 1816.7%
12:00 PM 1886.9%
1:00 PM 1696.2%
2:00 PM 1605.9%
3:00 PM 1324.9%
4:00 PM 1073.9%
5:00 PM 923.4%
6:00 PM 913.3%
7:00 PM 963.5%
8:00 PM 833.1%
9:00 PM 782.9%
10:00 PM 792.9%
11:00 PM 772.8%
Total 2717100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.54144
Monday 5.22339
Tuesday 4.28419
Wednesday 7.67637
Thursday 6.90607
Friday 5.48411
Saturday 5.33160
Total 5.842717

Hour1 Entry MadeAvg.Total
12:00 AM 5.0035
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 7.0035
8:00 AM 5.35107
9:00 AM 6.32278
10:00 AM 6.47246
11:00 AM 4.41181
12:00 PM 6.88330
1:00 PM 3.00111
2:00 PM 5.41222
3:00 PM 8.64285
4:00 PM 4.0589
5:00 PM 5.92154
6:00 PM 4.52113
7:00 PM 9.67174
8:00 PM 9.80147
9:00 PM 5.05111
10:00 PM 5.4265
11:00 PM 4.5732
Total 5.842717

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles