So our (beta) SDK sample includes a sizeable list of column names that you can ask for from the indexer (in the QueryBuilder.cs file)… but it’s far from a full list. These are the string constants that you pass to ExecuteQuery in the second parameter (and also you pass one of them as the third parameter to sort by). ExecuteQuery works like this:
_Recordset resultSet = foo.ExecuteQuery(“a query to search for“, “DocTitle, DocAuthor, Url“, “DocTitle“, null)
Let’s break those down:
Param 1: The first parameter is the query string, which is usually the user’s input. Now… you can take more control by modifying the user’s input. For example, if I’m building a music organizer, I might want to do this:
string foo = userInput + “ kind:music“;
Or if you’re like me (and use obscure file formats), userInput + “ fileext:(wma OR mp3 OR shn OR flac OR ogg OR mp4 OR aac)“ and so on =)
Param 2: This is the list of columns you want back - formatted as a comma delimited string. If you pass invalid column names or an improperly formatted string, the COM interface will throw an exception (so validate your input!). This is the SELECT portion of the SQL expression.
Param 3: This is the column you want the results ordered by. This directly becomes the ORDER BY clause so you’ll need to pass it in as “RecievedDate DESC” or “ReceivedDate ASC”. This value must be explicitly set to null (or Nothing in vb) if you don’t want the results sorted. Due to a bug in 2.5 passing an empty string (“”) will cause the method to fail.
Param 4: This is any optional constraint you want appended to the SQL expressions WHERE clause. Why do you need this? It let’s you filter the results to a particular type without have to append the AQS expression of “type:email” to the users query. To constrain the results to email you’d pass in “Contains(PerceivedType,’email’)”. This value must also be explicitly set to null if you don’t want any additional constraint applied. Due to a bug in 2.5 passing an empty string (“”) will cause the method to fail.
So how do you know what to send in the second and third parameters?
This is COMPLETEY UNSUPPORTED and all column names are SUBJECT TO CHANGE (and probably will) in future releases. Once again, our SDK and API are considered BETA components and are subject to change. Changing the registry can have very adverse effects on your system and do not attempt to use regedit unless you know what you’re doing.
We have the ability to log queries for support/diagnostic purposes by adding a DWORD to the registry named WriteLog under the key HKCU\Software\Microsoft\MSN Apps\DS and setting it to 1. As it turns out, the log that’s created is especially useful for developers. Once you’ve enabled logging, we log the SQL that is generated for every query in a file in your root path called “query.txt“
By running a query with this logging enabled, you can see the SQL that is generated. The SELECT statement will include all the columns that the UI asked for.
As I said above, the column names are probably going to change in future releases. While we do strive to keep from breaking things whenever possible, we have intentionally not documented these column names because we’re not ready to say that they’re final. Because of this please plan on future WDS releases changing these interfaces and the column names. No one here wants to make working with our stuff difficult for you, but for a fairly new product like ours we’re not yet comfortable with the burden that comes with promising future compatability on our current APIs - and we wouldn’t be repeating this disclaimer over and over if it wasn’t a serious concern for us.
This post was from my old blog. Click here for the original post (with original comments).
Some people in the Aqua-Soft forum had questions about how to call the Windows Desktop Search API from VB .NET. There are two ways to do this right now, using our beta SDK.
1) Download the SDK and Sample (see my post below) files. Reference WDSQuery.dll and include QueryBuilder.cs in your project. Then you can instantiate a QueryBuilder object and use that (the comments in that file, or IntelliSense, will guide you). It’s pretty simple.
OR
2) Use the COM API directly. Here’s what I posted over there:
Open VS 2003 and create a new VB.NET “Windows Forms” project. Add a reference to WDSQuery.dll.
Drop a DataGrid control from the toolbox onto the form, and size it reasonably. Leave the name as “DataGrid1″ for now.
Copy and paste this code into the vb file:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mSearchClass As New Microsoft.Windows.DesktopSearch.Query.SearchDesktopClass
Dim resultSet As Microsoft.Windows.DesktopSearch.Query._Recordset
resultSet = mSearchClass.ExecuteQuery(”test”, “DocTitle,DocAuthor,Url”, “DocTitle”, Nothing)
Dim DataSet1 As New System.Data.DataSet
Dim DataTable1 As New System.Data.DataTable
DataSet1.Tables.Add(DataTable1)
Dim DataAdapter1 As New System.Data.OleDb.OleDbDataAdapter
DataAdapter1.Fill(DataTable1, resultSet)
DataGrid1.DataSource = DataSet1
DataGrid1.DataMember = “Table1″
End Sub
Build and run. Your datagrid should be filled with results for the query “test” - you can of course change that to something more pertinent to your index.
VB isn’t really my thing, but that works on my system and should give you a basic idea of how to use the COM interfaces.
Option 1 is nice because QueryBuilder gives you easier query syntax to work with, and it gives you a decent list of Column Names that are supported in the current release (2.05) - remember, these are subject to change in future releases.
C# developers have a little easier time because they can read the sample code but not necessarily use it verbatim. If you don’t understand C# though it may not be as useful to you - it really depends on your usage.
I’ll be posting more about the SDK soon. Tomorrow my cable gets installed at the new apartment, so I’ll actually be able to leave the office and get more blogging done
[powered by WordPress.]
Hi. I'm Brandon. I'm a geek, and I work on Search technology for Windows at Microsoft. This is my blog.
The views expressed within my blog are my own - and are not in any way indicative of those of the company I work for, Microsoft, or it's employees. No warranties or other guarantees will be offered as to the quality of the opinions or anything else offered here.