Sunday, August 12, 2007

Get the keywords associated with a result item returned by Google Desktop Search

I've been programming with C# and Google Desktop Search (GDS) API for quite a while. Today, when I was browsing the Interop library of GDS (Interop.GoogleDesktopAPI.LIB) in Visual Studio 2008, I found that it's actually possible to obtain the keywords that Google Desktop has identified out of an indexed item. This hasn't been documented by Google GDS API guide yet. (I'm using GDS version 5.1.0707.23222-en-pb.)

Just call the function GetKeywords(int numKeywords, bool includeWeight) of any IGoogleDesktopQueryResultItem3 object and you'll get the keywords as a list of strings. Even better, if you set the input parameter includeWeight to true, then not only will you get the list of keywords, but following each keyword, you'll get the ranking score of that keyword as well.

A sample output for GetKeywords(10, true) is as follows:
papers:10.78 workshop:9.62 layout:9.01 university:8.18

Setting the input parameter 10 asks GDS to return the first 10 keywords, if there are more than 10. Notice that the keywords are always ranked by the ranking score in descending order.

One last thing, it's important to cast a result object to IGoogleDesktopQueryResultItem3, since only this version 3 result object has the GetKeywords() function.