I have a setup with two farms. Farm A is the front-end farm where web applications are hosted and farm B is the service farm where the search service + others are hosted. I have set up a custom content source and a custom scope (named "Teamsites") pointing to that content source. If I use the standard search center page I can query the scope without any issues, but when I use custom code (i.e. from within a web-part) to do a KeywordQuery with:
QueryText = "Scope=\"Teamsites\""
I get results even from outside the scope. As soon as I visit the viewscopes.aspx page on the site collection I'm querying from, however my custom query works fine. Is there some initialization I'm missing?
I've tried newing the KeywordQuery object both with SPContext.Current.Site and using the method described at the top of this article. Neither works unless I first visit the viewscopes.aspx page.
Edit: After nightly recycle the problem is back.
Here is how I'm initializing the KeywordQuery class:
var proxy = SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site); var keywordQuery = new KeywordQuery((SearchServiceApplicationProxy) proxy); keywordQuery.ResultTypes = ResultType.RelevantResults; keywordQuery.QueryText = "Scope=\"Teamsites\" AND contentclass=\"STS_Site\""; keywordQuery.RowLimit = 50; keywordQuery.Execute();
I've been wrestling with this for over a week now. Any help is greatly appreciated!
Edit2: I tried using FullTextSqlQuery with the same result.
Edit3: For completeness these are the methods I used to create scope and scope rule:
Edit4: I've now tried using the soap service search.asmx with the same result. It will not limit the search to the scope I specify.