Integration of your data sources with Windows 7 Federated Search

How often you should search for the various information? Most likely it occurs every day. It is important, that an information search problem not trivial. Also the information can is in various sources – in files, in e-mail messages, in documents etc. Not the secret, that most part of an information is in a network – local and global.

Windows Search which allows to search easily and conveniently on the basis of indexes has been developed in Windows Vista. In Windows 7 a theme of search has found the continuation and in new OS there was additional tool – Windows 7 Federated Search.

Windows 7 Federated Search is a tool which allows to search of information in a network within Windows Explorer. As a data source in this case can act anything you like – a corporate site, Internet shop, Internet auctions etc.

Difference between federated search and Windows Search consists that mechanisms of federated search do not index data sources, and simply call to them with the request to execute search query. Federated search is focused on the distributed remote sources of an information. Indexation of remote sources can be inefficient and lead to the excessive expense of the Internet traffic. For this reason the approach at which the task of processing of search query is assigned to a remote source. Thus, there is a possibility to connect all necessary remote sources and to search in them not leaving from Windows Explorer.

Despite all convenience of such search, implementation of the search provider is very simple. Federated search in Windows 7 is based on OpenSearch 1.1 standard, and works as follows. For search execution, the Windows 7 will call to the external web service constructed on the basis of the REST-approach. It means, that search query, and also other data necessary for search, are transferred in URI at the calling to this web service. Web-service on the basis of these data should execute search in the data source and will return result in RSS or AtomPub format. After that Windows 7 will present results of search from the received data in the form of files and will display to their user.

For addition of own search provider in Windows 7 it is necessary to create a file of the description of this provider. The format of this file is based on XML and contains the information on the given search service, including URI format for the calling to a web-service.

Thus, for implementation of own provider of federated search in Windows 7 it is necessary to execute two simple actions – to create REST-service for information search and to make for it a description file.

Let’s consider process of creation of the search provider on a following example. There is a list of books with the description, the author and other information. In this case this list contains in XML file (for a demonstration example). As a data source it is possible to use anything you like. Let’s make the search provider for this list.

The file of the description of a search provider represents a XML-file and has “.osdx” extension. This file has the following structure.

In Url section of this file the template of the address which will be used at the call to web service is set. It is visible, that this address can assume absolutely various representation. In the address template some sections in which values will be substituted are used. The main section is a “searchTerms” section. In this section the line for search will be substituted. Federated search in Windows 7 obtains data page by page, therefore there are sections “count” and “startIndex” which set the size and page number. It is necessary for, that Windows could receive the first results of search, display their to user, and then work with other elements.

The last, that it is necessary to make is to create service which will carry out search. In this case there is no binding to concrete technology and the only requirement – service should return result in RSS/Atom format. It is clear, that service can be constructed on absolutely various platforms and technologies. For these purposes the best choice – the usage of possibilities of WCF for creation of REST-services. A lot of attention is already given construction of similar services, therefore I will not stop in detail on it, and I will describe only key steps.

The first, that it is necessary to make is to define the contract. At the contract there will be two operations – execution of search and generating of the detailed information.

[ServiceContract]

[ServiceKnownType(typeof(Atom10FeedFormatter))]

[ServiceKnownType(typeof(Rss20FeedFormatter))]

publicinterface ISearchProvider

{

[OperationContract]

[WebGet(UriTemplate = "search/{searchTerms}/*")]

SyndicationFeedFormatter Search(string searchTerms);

[OperationContract]

[WebGet(UriTemplate = "details/{id}")]

Stream Description(string id);

}

The most important thing, on what it is necessary to pay attention during this moment – definition of URI template. Apparently in this case the “search/{searchTerms}/*” template completely corresponds to that has been defined in a description file.

It is necessary to implement this service only. At implementation it is necessary to consider the specified parametres at the call to service (searchTerms, start, count) and to divide search result into pages if it is necessary. For this purpose it is possible to use LINQ methods – Take/Skip. Thus, service implementation will look as follows.

publicclass SearchProvider : ISearchProvider

{

public SyndicationFeedFormatter Search(string searchTerms)

{

int count;

int startIndex;

int.TryParse(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters.Get("count"), out count);

int.TryParse(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters.Get("start"), out startIndex);

Also at service there are methods for display of the detailed information and search execution. At desire it is possible to download an example and to look their implementation there.

After service is ready and started, it is necessary to open a file of the description of service (.osdx) in Windows and to agree with offer to add the search provider. After that this provider will appear in the list of search providers.

Now, when web service works and also the provider of search is successfully added, it is possible to search on a network resource directly from Windows Explorer.

Apparently, implementation of the search provider for Windows 7 Federated Search is very simple. However, it can make use of your data much more conveniently and easier. One of the most successful examples of using of federated search in external sources is the search provider for corporate sites on the basis of Sharepoint. Why and to us not to implement similar functionality for our applications?