M_Parker_1170

I am attempting to run and capture search results programatically in WSS. I have found many references to doing this through search engines, but cannot get an example to work. Here is the best code i have attempted to use from the examples i have found:

Code Snippet

KeywordQuery qRequest = new KeywordQuery(SPContext.Current.Site);

qRequest.QueryText = "announcements";

ResultTableCollection resultTables = qRequest.Execute();

ResultTable relevantResults = resultTables[ResultType.RelevantResults];

DataTable resultsDataTable = new DataTable();

resultsDataTable.Load(relevantResults, LoadOption.OverwriteChanges);

When i run the above code, my ResultTableCollection doesn't have any records populated in it after the qRequest.Execute(); ( that is it has a count of 0 reflected ) and the ResultTable initialization gives an exception error "The given key was not present in the dictionary" -- i think that the exception is likely tied to the fact that the results table is null.

Help with this would be great.

Thanks,

Mike



Re: SharePoint - Search WSS KeywordQuery not working

Paul Galvin

This may be a silly question, but if you do a keywork search via the web browser for "announcements" do you get a result






Re: SharePoint - Search WSS KeywordQuery not working

M_Parker_1170

Not silly to be thorough. Answer is yes, i have searched same word used in code using interface search. Many hits were returned on GUI search.





Re: SharePoint - Search WSS KeywordQuery not working

Ariel Kirsman

I think WSS only supports RelevantQuery, but you need to explicitly set it:

qRequest.ResultTypes = ResultType.RelevantResults;





Re: SharePoint - Search WSS KeywordQuery not working

Puneet Narula - MSFT

In your code snippet add

qRequest.ResultType |= ResultType.RelevantResults;

before calling qRequest.Execute();

MOSS supports more values for result types but for WSS this is the only option.

Here is an example for doing keyword query for moss

http://msdn2.microsoft.com/en-us/library/ms493601.aspx

Documentation for ResultType enum values:

WSS: http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.search.query.resulttype.aspx

MOSS: http://msdn2.microsoft.com/en-us/library/microsoft.office.server.search.query.resulttype.aspx

-Puneet





Re: SharePoint - Search WSS KeywordQuery not working

M_Parker_1170

You are exactly right (well your comment got me going for the first tiem in about a whole day!)

Do you have any suggestions as to where i might "read up" on this keywordquerying

(thanks!)





Re: SharePoint - Search WSS KeywordQuery not working

Puneet Narula - MSFT

One decent link that I could find is:

http://msdn2.microsoft.com/en-us/library/bb608305.aspx

These are some visual how tos http://msdn2.microsoft.com/en-us/library/bb693435.aspx. Some of them are related to search but not necessarily to keyword query though.

The links in my previous post point to some documentation(which is being updated) in SDK

-Puneet