Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Search
Querying the Index
 Calling WDS Programmatically

  Switch on low bandwidth view
Calling WDS Programmatically

Microsoft Windows Desktop Search (WDS) 2.x can be queried programmatically using the ExecuteQuery and ExecuteSQLQuery methods in the ISearchDesktop interface. The ExecuteQuery method returns a record set from the index based on the query text, columns, and restrictions passed as parameters. The ExecuteSQLQuery method also returns a record set of results but requires the exact Structured Query Language (SQL) command to be passed in. ExecuteQuery should be used in most scenarios.

Regular Queries

Regular queries are those typed into the WDS input box by the user including all Advanced Query Syntax. The query is passed to ExecuteQuery along with the WDS 2.x schema columns to return, the column and order to sort results, and any clauses to restrict results by.

The method has the form:

HRESULT ExecuteQuery(LPCWSTR lpcwstrQuery, LPCWSTR lpcwstrColumn, LPCWSTR lpcwstrSort, LPCWSTR lpcwstrRestriction, Recordset **ppiRs);

DirectionVariableDescription
InlpcwstrQueryThe query text. This query is the same as a query typed into the search text box in the Windows Desktop Search user interface.
For example: "from:Zara dinner plans"
InlpcwstrColumnThe columns to include, separated by commas.
For example: "DocTitle, Url"
InlpcwstrSortThe Override Column to sort by followed by ASC for ascending or DESC for descending.
For example: "LastAuthor DESC"
InlpcwstrRestrictionRestrictions to append through WHERE clauses in the Windows Desktop Search select.
For example: "Contains(LastAuthor, 'Bill')"
OutppiRsThe resulting record set

SQL Queries

The ISearchDesktop.ExecuteSQLQuery method is used to send direct WDS database queries. The syntax for the queries is similar to that used for SharePoint Server, along with the ability to use Monarch-style SQL GROUP BY clauses. The query is executed against the index exactly as it is passed in with no additional processing of Advanced Query Syntax as the ExecuteQuery API does.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spssdk/html/_tahoe_search_sql_syntax.asp

The method has the form:

HRESULT ExecuteSQLQuery(LPCWSTR lpcwstrSQL, Recordset **ppiRs);

DirectionVariableDescription
InlpcwstrSQLThe SQL query to execute against the WDS index
OutppiRsThe resulting record set

Resources:

  • Support files for the ISearchDesktop interface: http://addins.msn.com/support/WDSSDK.zip
  • ISearchDesktop C# Sample: http://addins.msn.com/support/WDSSample.zip

Sample C++ Code

Note  

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

Copyright (c) Microsoft Corporation. All rights reserved.

#include <stdio.h>
#include <wchar.h>
#include <windows.h>
#include <msnldl.h>
#include <adoint.h>
#include <adoguids.h>
 
HRESULT TestExecuteQuery(ISearchDesktop *psd)
{
ADORecordset *prs = NULL;
 
    HRESULT hr;
 
    hr = psd->ExecuteQuery( L"ToName:Moishe", 
                            L"DocTitle,DocFormat", 
                            L"PrimaryDate DESC", 
                            L"Contains('text')", 
                            &prs);
    if (SUCCEEDED(hr))
        prs->Release();
    return hr;
}
 
HRESULT TestExecuteSQLQuery(ISearchDesktop *psd)
{
    ADORecordset *prs = NULL;
    HRESULT hr;

    hr = psd->ExecuteSQLQuery(L"select DocTitle from MyIndex..Scope() where contains('text')", &prs);

    if (SUCCEEDED(hr))
      prs->Release();
    return hr;
}
 
extern "C" int __cdecl wmain( int argc, WCHAR * argv[] )
{
    SCODE sc = CoInitialize(0);
    ISearchDesktop *psd = NULL;
    HRESULT         hr;
     
    if (SUCCEEDED(hr = CoCreateInstance(__uuidof(SearchDesktop), NULL, CLSCTX_INPROC_SERVER, 
                                        __uuidof(ISearchDesktop), (void**)&psd)))
          {
             TestExecuteSQLQuery(psd);
             TestExecuteQuery(psd);
             psd->Release();
          }
          CoUninitialize();
}

Related Topics

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker