Using ISearchQueryHelper from managed code
ISearchQueryHelper is a COM interface that can be used to convert from Advanced Query Syntax (AQS) to a SQL query that can be passed to the OLE DB Provider for Windows Search. (For background, see my previous post: Advanced Query Syntax: What, Where, Why, and How)
Good news for managed code developers - there's a type library from which you can create an interop assembly (using the tlbimp.exe tool). You'll find the type library (it's called SearchAPI.tlb) in the Lib folder of the Windows SDK.
Once you've generated an interop assembly and have added a reference to it from your managed code project, here are the necessary steps to convert from AQS to SQL syntax:
- Instantiate the Search Manager
- Get the catalog manager for the system index
- Query the catalog manager for its corresponding query helper
- Convert an AQS string to a SQL query string
Here's some C# code that shows how to convert an AQS string to a SQL query string (the code fragment assumes that aqsQuery is a string variable that contains an AQS query):
using SearchAPILib;
...
CSearchManager manager = new CSearchManagerClass();
CSearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");
CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
string sqlQuery = queryHelper.GenerateSQLFromUserQuery(aqsQuery);
Comments
- Anonymous
June 18, 2007
Apologies for the delay of this post, I’ve been busy with MIX07. Charles Torre and I organized the MIX07