asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

An Introduction to OpenSearch
By John Peterson
Rating: 4.4 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article



    What is OpenSearch?

    According to the OpenSearch.org official website:

    OpenSearch is a collection of simple formats for the sharing of search results.

    You're more likely to know it as the format that websites use in order to let you access their search engines directly from the search box in Internet Explorer (IE) 7 and Firefox 2.0.

    While OpenSearch actually specifies a number of formats which are useful in many different scenarios, this article assumes that you run a website and want to use OpenSearch to point visitors to your search engine. To that end, I'll be touching upon the the following topics:

    • Creating an OpenSearch description document for your search engine.
    • Adding autodiscovery links to your web site so people can easily find your OpenSearch description document.
    • Specifying an icon or logo that search clients can display along with your search.

    All the information and examples in this article use the most recent version of the OpenSearch specification which as of this writing is OpenSearch 1.1 (Draft 3).

    The search box in IE 7
    The search box in IE 7

    The search box in Firefox 2.0
    The search box in Firefox 2.0

    OpenSearch Description Document

    The first step in making your site's search engine accessible via OpenSearch is to create what's called an OpenSearch description document. An OpenSearch description document is simply an XML file that describes your search's interface. There are many optional elements which you can add if you want to, but in its basic form an OpenSearch description document looks something like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
        <ShortName>15Seconds</ShortName>
        <Description>Search for .NET solutions and information at 15Seconds.com</Description>
        <Tags>15Seconds 15 Seconds ASP ASP.NET .NET</Tags>
        <Contact>webmaster@15seconds.com</Contact>
        <Url type="text/html"
            template="http://www.15seconds.com/search/search.asp?query={searchTerms}&amp;start={startIndex?}"
        />
        <Query role="example" searchTerms="asp.net" />
    </OpenSearchDescription>

    Most of the elements are pretty self-explanatory and when creating your own OpenSearch description document you should obviously replace the sample values I've included above with values which more accurately reflect the characteristics of the search to which the document points. In particular, please change the email address... we already get quite enough email.  ;)

    The two elements which do warrant a brief explanation are Url and Query.

    The Url element is used to describe an interface which a client can use to request search results. If you're simply trying to allow users to search your site via OpenSearch, then you'll only need a Url element with a type attribute of "text/html" as shown in the example above.

    Note: Although most of you won't need to include more then one, it is perfectly acceptable for a OpenSearch description document to contain multiple Url elements. For example, if search results are also available as XML, RSS, or Atom, you would create a Url element for each and in the type attribute you would include the MIME type which indicates the format in which the search results are returned.

    The Url element's template attribute is where the real magic happens. This is where you provide the URL and format that search clients should use to query your search engine. OpenSearch 1.1 defines a number of parameters which you can use as placeholders in the template. The most important of these is the "searchTerms" parameter which is replaced by the keyword(s) for which the client is searching. In the example above, I've also included the "startIndex" parameter as an optional template parameter. You indicate that the parameter is optional by adding the "?" character to the end of the parameter name. The search client will use an empty string as a value if no value is specified for an optional parameter.

    The Query element is used to define a search that a client can perform. In our scenario it's not all that useful, but in more complex applications you can use the Query element to pass parameters (ie. spelling corrections, number of search results, or related search terms) back to the client. The Query element in our sample description document has the role of "example" which indicates that it's simply included to provide search clients with a sample query with which to test the search engine. Whatever example terms you provide are expected to return search results.

    That should be all the information you need in order to create an OpenSearch description document for your site's search engine, but if you find you need any more information the best place to turn is to the OpenSearch description document section of the OpenSearch 1.1 specification.

    Autodiscovery Links

    So now that you've created your OpenSearch description document and uploaded it to your web site, how do you let people know where it is? That's where autodiscovery links come into the picture. For HTML it really couldn't be much simpler. Simply add a profile attribute and a link element to the head section of your web page that references the related OpenSearch description document which you just created.

    <head profile="http://a9.com/-/spec/opensearch/1.1/">
        ...
        <link
            rel="search"
            type="application/opensearchdescription+xml"
            href="/search/opensearch1.1.xml"
            title="15 Seconds"
        />

        ...
    </head>

    The sections in red are the parts you'll need to add to your existing HTML document. The values for the profile, rel, and type attributes are fine as they are above. The href attribute should point to your OpenSearch description document and the title attribute should be changed to the name of your search.

    Once you've added the code above to your HTML file, when you load the file in a browser you'll notice a couple of things. Near the search box there's usually a subtle indication that the page you're on contains a link to a description document. In IE 7, the arrow next to the search button gets an orange-ish tint, while in Firefox 2.0 it's more of a blue-green haze around the currently selected search provider's icon.

    IE 7 search box without (top) and with (bottom) autodiscovery link
    IE 7 search box without (top) and with (bottom) autodiscovery link

    Firefox 2.0 search box without (top) and with (bottom) autodiscovery link
    Firefox 2.0 search box without (top) and with (bottom) autodiscovery link

    If you then click on the highlighted button, you'll have the option to add your search provider to the search bar.

    Add Search Provider -> 15 Seconds (IE 7)
    Add Search Provider -> 15 Seconds (IE 7)

    Add "15 Seconds" (Firefox 2.0)
    Add "15 Seconds" (Firefox 2.0)

    Once they've added your search provider to the browser the user can search your site directly from the search box anytime they want.

    Just as with the OpenSearch description document, any additional infomation you may need is probably best obtained from the autodiscovery section of the OpenSearch 1.1 specification.

    How Do I Get My Logo To Show Up?

    You'll notice that while Internet Explorer simply lists the short name of the different search providers, Firefox takes things one step further and actually displays a small icon next to the different providers. If your site already has a "favicon.ico" file in the site's root directory, Firefox will most likely find and use the file automatically. If the file is named something else, isn't located in the root folder, or you simply wish to use a different image, you can specify an "Image" element in your OpenSearch description document.

        ...
        <Image width="16" height="16" type="image/vnd.microsoft.icon">http://www.15seconds.com/favicon.ico</Image>
        ...

    You can also specify multiple images of different sizes and in different formats. For more information see The "Image" element section of the OpenSearch 1.1 specification.

    Where Can I Learn More?

    As you've probably guessed the best place to learn more about OpenSearch is from the official site, but Wikipedia also offers a good overview. I'm also including links to the search add-in pages for both IE7 and Firefox.

    Conclusion

    I hope this article has helped open your eyes to just how easy it is to get started using OpenSearch. Along with the basics I've already covered, OpenSearch 1.1 offers a lot more if you've got a use for it. If you're looking to share search results either as a provider or as a consumer, you really should take a closer look at the technology. In addition to defining response elements to provide search metadata when results are returned in an XML-based format, the specification includes a number of extensions to provide everything from relevance weighting and suggestions to a new Geo extension which aims to to provide a standard way to query based on geographical location.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 21, 2005 - N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005 - Part 1
    While the .NET Framework made building ASP.NET applications easier then it had ever been in the past, .NET 2.0 builds on that foundation in order to take things to the next level. This article shows you to how to construct an N-Tier ASP.NET 2.0 Web application by leveraging the new features of ASP.NET 2.0 and SQL Server 2005.
    [Read This Article]  [Top]
    Apr 28, 2005 - New Files and Folders in ASP.NET 2.0
    With the release of ASP.NET 2.0, Microsoft has greatly increased the power of ASP.NET by introducing a suite of new features and functionalities. As part of this release, ASP.NET 2.0 also comes with a host of new special files and folders that are meant to be used to implement a specific functionality. This article examines these new files and folders in detail and provides examples that demonstrate how to utilize them to create ASP.NET 2.0 applications.
    [Read This Article]  [Top]
    Mar 10, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2, Cont'd
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 9, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 3, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1, Cont'd
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Mar 2, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Feb 16, 2005 - Writing a Custom Membership Provider for the Login Control in ASP.NET 2.0
    In ASP.NET 2.0 and Visual Studio 2005, you can quickly program custom authentication pages with the provided Membership Login controls. In this article, Dina Fleet Berry examines the steps involved in using the Login control with a custom SQL Server membership database.
    [Read This Article]  [Top]
    Dec 29, 2004 - ClickOnce Deployment in .NET Framework 2.0
    In this article, Thiru Thangarathinam examines .NET 2.0's new ClickOnce deployment technology that is designed to ease deployment of Windows forms applications. This new technology not only provides an easy application installation mechanism, it also eases deployment of upgrades to existing applications.
    [Read This Article]  [Top]
    Dec 15, 2004 - A Sneak Peek at ASP.NET 2.0's Administrative Tools
    With ASP.NET 2.0, Microsoft has made great strides in increasing developer productivity and has made implementing previously complex solutions relatively easy. Where this version of ASP.NET really shines, however, is in its new administrative tools that allow developers to spend less time managing the configuration of the servers and software and more time developing great code.
    [Read This Article]  [Top]
    Nov 17, 2004 - The ASP.NET 2.0 TreeView Control
    Thiru Thangarathinam introduces ASP.NET 2.0's new TreeView control which provides a seamless way to consume and display information from hierarchical data sources. The article discusses this new control in depth and explains how to use this feature rich control in your ASP.NET applications.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.commediabistro.comJusttechjobs.comGraphics.com

    Search:

    WebMediaBrands Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs