A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, MOSS 2007, ASP.NET, LINQ, and Visual Studio 2012.
Today I realized that when I blogged about how to use the KeywordQuery class, I forgot to mention how to specify the scope(s) you are querying. You would think there would be a built-in property to set this, but there isn't. I wanted to see how Microsoft was doing it so I used reflector and examined the notorious SearchResultsHiddenObject that the CoreResultsWebPart uses. It in fact does what I expected. It simply iterates through the list of scopes and appends each one to the keyword query string (i.e.: Scope:"Working Documents"). I was hoping there would be a more elegant way of doing this, but this appears to be the way.
About CoreyRoth
Corey Roth is an Applications Architect at Infusion specializing in ECM and Search.