Integrating your data sources with federated search in Windows 7 is easy!
How often do you have to look for various information? Most likely this happens every day. It should be noted that the task of finding information is far from trivial. The situation is complicated by the fact that information can be found in completely different sources - in files, in e-mail messages, in documents, etc. It is no secret that most of the information is on the network - local and global.
To simplify the search for information in Windows Vista, the Windows Search tool was developed, which allows you to easily and conveniently search for information based on pre-prepared indexes. In Windows 7, the search topic continued, and the Windows 7 Federated Search tool appeared in the new operating system.
Windows 7 Federated Search is a tool that allows you to search for information on a network based on Windows Explorer. In this case, anything can serve as a data source - a corporate website, an online store, online auctions, etc.
The difference between federated search and Windows Search is that federated search engines do not index data sources, but simply contact them with a request to perform a search query. Federated search focuses specifically on distributed remote information sources. When it comes to remote sources, their indexing can be inefficient and lead to excessive traffic consumption. That is why an approach was chosen in which the task of processing a search query rests on the shoulders of a remote source. Thus, it becomes possible to connect all remote sources and search through them without leaving the familiar Windows Explorer.
Despite the convenience of such a search, implementing a search provider is a very simple task. Federated search in Windows 7 is based on the OpenSearch 1.1 standard and works as follows. To search, Windows 7 uses an external web service built on the basis of the REST approach. This means that the search string, as well as other data necessary for the search, is transferred to the URI when accessing this web service. Based on this data, the web service should search in its data source and return the result in RSS or AtomPub format. After that, Windows 7 will present the search results from the received data in the form of files and display them to the user.
To add your search provider in Windows 7, you must create a description file for that provider. The format of this file is based on XML and contains information about this search service, incl. URI format for accessing the service.
Thus, to implement your own federated search provider in Windows 7, you need to perform two simple steps - create a REST service for finding information and make a description file for it.
Let's look at the process of creating a search provider using the following example. There is a list of books with a description, author and other information. In this case, this list is contained in an XML file (for a demo). You can use anything you want as a data source. We will make a search provider on this list.
The search provider description file is an XML file and has the extension “.osdx”. This file has the following structure.
In the Url section of this file, an address template is set that will be used when accessing the web service. It can be seen that this address can take a completely different look. The address template uses several sections into which values will be substituted. The main section is the “searchTerms” section. In this section, a string will be substituted for the search. Windows 7 Federated Search retrieves data one page at a time, so there are “count” and “startIndex” sections that specify page size and page number. This is necessary in order for Windows to be able to get the first search results, display them to the user, and then do the rest of the elements.
In the demo, a web service will be created that will be hosted on the local machine. For this reason, the search provider description file will be as follows.
The last thing you need to do is create the service itself that will perform the search. In this case, there is no binding to a specific technology and the only requirement is that the service must return the result in RSS / Atom format. It is clear that the service itself can be built on completely different platforms and technologies. It can be PHP, Ruby, Native CGI, etc. If we consider the set of technologies for building REST services from Microsoft, then the best choice in this case is to use the WCF capabilities for building REST services. A lot of attention has already been paid to the construction of such services, so I will not dwell on this in detail, but will describe only the key steps.
The first thing to do is determine the contract. The contract will include two operations - performing searches and obtaining detailed information.
The most important thing you need to pay attention to at this point is the definition of the URI template. As you can see in this case, the pattern “search / {searchTerms} / *” fully corresponds to what was defined in the description file.
It remains only to implement this service. When implementing, it is necessary to take into account the specified parameters when accessing the service (searchTerms, start, count) and break the search result into pages, if necessary. The LINQ - Take / Skip methods are ideal for this. Thus, the implementation of the service will look as follows. The service also has methods for displaying detailed information and performing a search. If you wish, you can download an example and see their implementation there.
After the service is ready and running, you must open the service description file (.osdx) in Windows and accept the offer to add a search provider. After that, this provider will appear in the general list of search providers.
Now that the web service is running and the search provider has been successfully added, you can search on a network share directly from Windows Explorer. You can also use the preview window. By default, content is loaded into it, which is located at the address to which this item refers (in the demo application, it is “/ details / {id}”). This address may contain HTML content that will be displayed to the user.
As you can see, the implementation of the search provider for Windows 7 Federated Search is very simple, however, it can make using your data much more convenient and easier. One of the most successful examples of implementing federated search by external sources is the search provider for corporate sites based on Sharepoint. Why don't we implement similar functionality for our applications?
Sample Application:
FederatedSearchProviderSample.zip
To simplify the search for information in Windows Vista, the Windows Search tool was developed, which allows you to easily and conveniently search for information based on pre-prepared indexes. In Windows 7, the search topic continued, and the Windows 7 Federated Search tool appeared in the new operating system.
Windows 7 Federated Search is a tool that allows you to search for information on a network based on Windows Explorer. In this case, anything can serve as a data source - a corporate website, an online store, online auctions, etc.
The difference between federated search and Windows Search is that federated search engines do not index data sources, but simply contact them with a request to perform a search query. Federated search focuses specifically on distributed remote information sources. When it comes to remote sources, their indexing can be inefficient and lead to excessive traffic consumption. That is why an approach was chosen in which the task of processing a search query rests on the shoulders of a remote source. Thus, it becomes possible to connect all remote sources and search through them without leaving the familiar Windows Explorer.
Despite the convenience of such a search, implementing a search provider is a very simple task. Federated search in Windows 7 is based on the OpenSearch 1.1 standard and works as follows. To search, Windows 7 uses an external web service built on the basis of the REST approach. This means that the search string, as well as other data necessary for the search, is transferred to the URI when accessing this web service. Based on this data, the web service should search in its data source and return the result in RSS or AtomPub format. After that, Windows 7 will present the search results from the received data in the form of files and display them to the user.
To add your search provider in Windows 7, you must create a description file for that provider. The format of this file is based on XML and contains information about this search service, incl. URI format for accessing the service.
Thus, to implement your own federated search provider in Windows 7, you need to perform two simple steps - create a REST service for finding information and make a description file for it.
Let's look at the process of creating a search provider using the following example. There is a list of books with a description, author and other information. In this case, this list is contained in an XML file (for a demo). You can use anything you want as a data source. We will make a search provider on this list.
The search provider description file is an XML file and has the extension “.osdx”. This file has the following structure.
Federated Search sample provider
In the Url section of this file, an address template is set that will be used when accessing the web service. It can be seen that this address can take a completely different look. The address template uses several sections into which values will be substituted. The main section is the “searchTerms” section. In this section, a string will be substituted for the search. Windows 7 Federated Search retrieves data one page at a time, so there are “count” and “startIndex” sections that specify page size and page number. This is necessary in order for Windows to be able to get the first search results, display them to the user, and then do the rest of the elements.
In the demo, a web service will be created that will be hosted on the local machine. For this reason, the search provider description file will be as follows.
Federated Search sample provider
The last thing you need to do is create the service itself that will perform the search. In this case, there is no binding to a specific technology and the only requirement is that the service must return the result in RSS / Atom format. It is clear that the service itself can be built on completely different platforms and technologies. It can be PHP, Ruby, Native CGI, etc. If we consider the set of technologies for building REST services from Microsoft, then the best choice in this case is to use the WCF capabilities for building REST services. A lot of attention has already been paid to the construction of such services, so I will not dwell on this in detail, but will describe only the key steps.
The first thing to do is determine the contract. The contract will include two operations - performing searches and obtaining detailed information.
[ServiceContract]
[ServiceKnownType(typeof(Atom10FeedFormatter))]
[ServiceKnownType(typeof(Rss20FeedFormatter))]
public interface ISearchProvider
{
[OperationContract]
[WebGet(UriTemplate = "search/{searchTerms}/*")]
SyndicationFeedFormatter Search(string searchTerms);
[OperationContract]
[WebGet(UriTemplate = "details/{id}")]
Stream Description(string id);
}
The most important thing you need to pay attention to at this point is the definition of the URI template. As you can see in this case, the pattern “search / {searchTerms} / *” fully corresponds to what was defined in the description file.
It remains only to implement this service. When implementing, it is necessary to take into account the specified parameters when accessing the service (searchTerms, start, count) and break the search result into pages, if necessary. The LINQ - Take / Skip methods are ideal for this. Thus, the implementation of the service will look as follows. The service also has methods for displaying detailed information and performing a search. If you wish, you can download an example and see their implementation there.
public class 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);
var result = SearchBooks(searchTerms);
if (count > 0)
{
if (startIndex >= 0)
{
result = result.Skip(count * (startIndex - 1)).Take(count);
}
else
{
result = result.Take(count);
}
}
return new Rss20FeedFormatter(
new SyndicationFeed("Federated search sample", String.Empty, null,
from item in result
select new SyndicationItem(item.Element(XName.Get("name")).Value,
item.Element(XName.Get("description")).Value,
new Uri(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.BaseUri.ToString() + @"/details/" + item.Element(XName.Get("id")).Value))
{
PublishDate = DateTimeOffset.Parse(item.Element(XName.Get("date")).Value),
}));
}
//...
}
After the service is ready and running, you must open the service description file (.osdx) in Windows and accept the offer to add a search provider. After that, this provider will appear in the general list of search providers.
Now that the web service is running and the search provider has been successfully added, you can search on a network share directly from Windows Explorer. You can also use the preview window. By default, content is loaded into it, which is located at the address to which this item refers (in the demo application, it is “/ details / {id}”). This address may contain HTML content that will be displayed to the user.
As you can see, the implementation of the search provider for Windows 7 Federated Search is very simple, however, it can make using your data much more convenient and easier. One of the most successful examples of implementing federated search by external sources is the search provider for corporate sites based on Sharepoint. Why don't we implement similar functionality for our applications?
Sample Application:
FederatedSearchProviderSample.zip