Geeks With Blogs


Microsoft Store

Support This Site

AddThis Social Bookmark Button

Locations of visitors to this page

Subscribers to this feed

TwitterCounter for @sdorman

Creative Commons License

Scott Dorman Microsoft MVP, Software Architect, Developer, Author

Earlier today, I talked about Live Search and how to add a Live Search Box to your website.

In those posts, I talked about the 3-step wizard that allows you to easily add the Advanced Search Box to your site and the fact that it doesn't allow you to specify multiple search macros.

If you look at the search results from my blog now, you will see that there are now 5 new tabs in the search results. (Before I only had 2, "My blog" and "Web".) These tabs show search results from the entire GeeksWithBlogs site, MSDN, MSDN Blogs, MSDN Forums, the Microsoft Support site, and the entire web.


You still can't add the additional macros using the wizard, but if you don't mind customizing the Javascript that it generates, you can add them by hand. It's best if you know Javascript, at least a little bit, but I don't think it's a requirement. No matter what, you should make a backup copy of either the original script or the entire page just in case something goes wrong.

In the Javascript, you will see a section that looks like this:

   1: var WLSearchBoxConfiguration=
   2:       {
   3:          "global":{
   4:             "serverDNS":"",
   5:             "market":"en-US"
   6:          },
   7:          "appearance":{
   8:             "autoHideTopControl":false,
   9:             "width":800,
  10:             "height":550,
  11:             "theme":"Blue"
  12:          },
  13:          "scopes":[
  14:             {
  15:                "type":"web",
  16:                "caption":"My blog",
  17:                "searchParam":"\/sdorman"
  18:             }
  19:             ,
  20:             {
  21:                "type":"web",
  22:                "caption":"Web",
  23:                "searchParam":""
  24:             }
  25:          ]
  26:       }

The part that we need to modify is the "scopes" declaration. This section effectively declares an array of search scopes, including the type, caption, and search parameters. You can add as many scope definitions as you want to this section, but make sure you only have one definition for searching the entire web (this is the definition that has an empty searchParam specification). If you decide to add multiple search macros,  you can find a bunch of predefined macros on the Windows Live Gallery or you can make your own. Be sure to separate the definitions with a comma (,) to prevent Javascript errors.

As you can see, the caption is specified by using the Hex values for the letters. It will work using normal English letters, but I don't think it will be translated properly. If you want to easily find the Hex values, you can use this String to ASCII/Hex/Binary online converter. Once you get the Hex string, you will need to make the hex values proper HTML entities by adding the "&#x" in front of the hex value and the ";" after it. The other thing to watch out for is that this creates an entity of  for a space instead of the correct   entity.

For example, to add an additional search macro that searches MSDN, you need to add the following bit of code:

   1: {
   2:    "type":"web",
   3:    "caption":"MSDN",
   4:    "searchParam":"macro:livelabs.msdn"
   5: }

The same thing will work for adding additional sites, all you need to do is change the searchParam specification. For example, to search the entire Microsoft site, you would add the following:

   1: {
   2:    "type":"web",
   3:    "caption":"Microsoft",
   4:    "searchParam":""
   5: }

You can create more advanced searchParam specifications, but I highly recommend creating a macro if you are going to do that.

Posted on Sunday, October 21, 2007 2:37 PM General | Back to top

Copyright © Scott Dorman | Powered by: