Vista Search for Developers
As for Vista the Windows Desktop search is now fully integrated into the OS, there are several ways to take advantage of it:
a) Plugin your data sources into the searchindex
Vista search is capable of searching all kinds of file formats and storage locations. This is done via some sort of adapter concept: You need to implement a ProtocolHandler to plugun your custom store (like mapi, ftp, filesystem) into the search.
Moreover a class implementing IFilter defines the logic, how to search data within your file (e.g. the file format of an outlook .PST file). Those classes should be written in C++ (without .NET) - see the explaination here.
Links: Introduction to IFilter, IFilter Blog, Overview of Protocol Handlers
b) Consuming the searchindex
Out of your managed application you can consume the search - meaning you can search items in the index.
The search is done via an OleDbConnection with standard ADO.NET. You need to specify a special connection string:
"Provider=Search.CollatorDSO;Extended Properties='Application=Windows'"
Then you can do SELECT queries, where you always need to explicitely specify the columns/properties to be selected. A nice option is searching remote indices (as long as they are running on Vista or Windows 2008 Server) by simply specifying a remote host:
SELECT <properties>
FROM [machineName.]SYSTEMINDEX..SCOPE()
[WHERE <predicates>]
SELECT "System.ItemNameDisplay", "System.Kind" FROM SYSTEMINDEX WHERE "System.Kind" like 'Music'
Column names are written in double quotes, whereas string values in single quotes. The WHERE clause may contain the simple predicates LIKE,=,<,>, IS [NOT] NULL as well as the fulltext predicates CONTAINS and FREETEXT.
They both have a similar syntax:
CONTAINS | FREETEXT (' <searchString> ') searches within the contents of items
CONTAINS | FREETEXT (" <column>" , ' <searchString> ') searches within a given property
CONTAINS | FREETEXT (* , ' <searchString> ') searches contents and all properties
Samples are
CONTAINS("System.FromName", '"Max Knor"')
Use double quotes for column names, single quotes for search string, in the search string use double quotes to mark coherent words
CONTAINS("System.FromAdress", '*microsoft.com')
Use FREETEXT if you care about relevancy– it’s the only predicate that returns a meaningful rank value. (All other predicates return 0 or 1000, depending on the whether there was a match or not). (Hint: to get the rank value, include System.Search.Rank in the select list).
When querying some properties, you get back string-arrays (e.g. for System.Kind), even if they only have one value. You need to convert them to a string, to display them correctly.