A number of people have been asking about Windows Vista search and how to programmatically query the search engine. There's not a lot of documentation available yet (and this will obviously change as we near the release of Windows Vista). So in the meantime, here's a quick primer for those of you that would like to get started today.
BackgroundWindows Vista includes a built-in desktop indexing platform. You’ll see search integrated throughout Windows Vista, in all the Explorer windows and even in the Start menu. A number of Microsoft products are building on top of this infrastructure - like Outlook 2007 and OneNote 2007, just to name a couple.
Your applications can also plug into this same infrastructure and query the index, by using the new OLE DB Provider for Windows Search. (There are also extensibility mechanisms by which you can expose data to the indexer, but I'll leave that for a future post)
The Windows Vista search and indexing infrastructure will also be available as a download for Windows XP and Windows Server 2003. You can download the Windows Desktop Search 3.0 Beta Engine Preview here.
Using the OLE DB Provider for Windows SearchWhile there's a lot of information available on OLE DB, you won't get very far with that alone – you also need to know the specifics of the provider, like its connection string and its query syntax. (If you're using ADO.NET, just a reminder that you can use the types defined in the System.Data.OleDb namespace. If you don't know how to use an OLE DB provider, a good place to start would be the MSDN Data Access and Storage Developer Center.)
Here's the connection string for the OLE DB Provider for Windows Search:"Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"
The query syntax is what I've found to be the trickiest part, and that's what I'll focus on for the rest of this post.
StatementsThe OLE DB Provider for Windows Search supports a single statement: the SELECT statement. The provider was designed solely for read-only operations, so there's no need for INSERT, UPDATE or DELETE statements.
The structure of the SELECT statement looks like this:SELECT <properties> FROM [machineName.]SYSTEMINDEX..SCOPE() [WHERE <predicates>]
SELECT <properties><properties> represents a list of one or more comma separated "column" names, where the columns correspond to properties defined in the new Windows Vista property system.
Here are a couple of details about the SELECT clause that may not be obvious:
FROM [machineName.]SYSTEMINDEX..SCOPE()The FROM clause is pretty straightforward; since there's only a single index that can be queried, there's only one possible variation: you can precede SYSTEMINDEX..SCOPE() with a machine name to execute a query against the local index of a remote machine. (You must be running Windows Vista or Longhorn Server on the remote machine, and there are configuration steps/permissions that must be done before this will work).
[WHERE <predicates>]The optional WHERE clause supports a number of predicates.
In my next post, I'll cover some details about the predicates and I'll provide some specific examples of their usage.