Tag Archives: KeywordQuery SharePoint

Handy Reference: Default Results from KeywordQuery Search

When you invoke the Execute() method on a KeywordQuery, you can create a ResultTable based on ResultType.RelevantResults.  This code snippet illustrates what I mean:

ResultTableCollection resultsTableCollection = myKeywordQuery.Execute();

ResultTable searchResultsTable = resultsTableCollection[ResultType.RelevantResults];

The resulting table will have the following columns of information: 

WorkId
Rank
Title
Author
Size
Path
Description
Write
SiteName
CollapsingStatus
HitHighlightedSummary
HitHighlightedProperties
ContentClass
IsDocument
PictureThumbnailURL
ServerRedirectedURL

I derived this list from a SharePoint 2010 environment, enterprise edition.  Hopefully it will be handy to someone in future.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

SharePoint 2010 KeywordQuery and the HiddenConstraints Property

I’ve been doing a bit of work with the KeywordQuery object in SharePoint 2010 and making use of the HiddenConstraints property.

I didn’t find any immediately helpful information on the that property, so I thought I’d quickly jot down how I’ve been using it.

As far as I can tell, this is an automatic constraint added to the query so that you can sort of park it there and not worry about it.  As such, it’s just another keyword (or set of keywords) and modifiers that you can type in to the UI when you do a keyword search.  Here’s an example:

keywordQuery.HiddenConstraints = "scope:\"Industry\"";

You can add additional constraints with a space delimiter.

keywordQuery.HiddenConstraints = "scope:\"Industry\" defense";

The above is saying in English, “run a keyword query looking for “defense” and furthermore, use the “Industry” scope.

Here’s another way of looking at it:

image

I’ve been using it to provide a context-dependent automatic scope on a custom web part.  When the user clicks on a tab and clicks a search button, the tab dictates a particular search scope.  It’s working well so far.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin