Using the Search API with Sharepoint Foundation 2010 Results - 0
I am a sharepoint newbee and am unable to get search results to be returned using the search API in the Sharepoint 2010 Foundation.
Here are the steps I've taken so far.
- Sharepoint Foundation Search v4 service runs and logs on as a local service
- Under Team Site - Site Settings - Search & Offline Accessibility, Site Content Indexing is enabled.
- Run PowerShell script Get-SPSearchServiceInstance returns
Enter the name: SharePoint Foundation Search
Description: Search for the index file on the search server
Id: 91e01ce1-016e-44e0-a938-035d37613b70
Server: SPServer Name = V-SP2010
Service: SPSearchService name = SPSearch4
IndexLocation: C: \ Program Files \ Common Files \ Microsoft Shared \ Web Server Exten this \ 14 \ Data \ Applications
ProxyType: Default
Status: online
- When I search using the search text box on the team site, I get the results as I expected.
Now, when I try to duplicate search results using the search API, I get an error or 0.
Here's some sample code:
using Microsoft.SharePoint.Search.Query;
using (var site = new SPSite(_sharepointUrl, token))
{
//
FullTextSqlQuery fullTextSqlQuery = new FullTextSqlQuery(site)
{
QueryText = String.Format("SELECT Title, SiteName, Path FROM Scope() WHERE \"scope\"='All Sites' AND CONTAINS('\"{0}\"')", searchPhrase),
//QueryText = String.Format("SELECT Title, SiteName, Path FROM Scope()", searchPhrase),
TrimDuplicates = true,
StartRow = 0,
RowLimit = 200,
ResultTypes = ResultType.RelevantResults
//IgnoreAllNoiseQuery = false
};
ResultTableCollection resultTableCollection = fullTextSqlQuery.Execute();
ResultTable result = resultTableCollection[ResultType.RelevantResults];
DataTable tbl = new DataTable();
tbl.Load(result, LoadOption.OverwriteChanges);
}
When All Sites is set to All Sites, I get an error when the search scope is not available. Another search just returns 0 results.
Any ideas on what I am doing wrong?
source to share
This is the workaround we ran into.
-
We didn’t get the job search we had hoped for. We'll look at it again after the release of the RTM version of the Sharepoint Foundation.
-
We installed the beta version of Search Server Express 2010. This allowed us to use the office server namespaces and associated classes. This worked as expected and we were able to program the search over the Sharepoint Foundation.
source to share
I also never got results using FullTextSqlQuery in Foundation Search, but maybe you can use KeywordQuery:
SPSite thisSite = SPControl.GetContextSite(Context);
Microsoft.SharePoint.Search.Query.KeywordQuery kwQuery = new Microsoft.SharePoint.Search.Query.KeywordQuery(thisSite);
kwQuery.RowLimit = 1000;
kwQuery.QueryText = "searchString";
kwQuery.HiddenConstraints = "site:\"http://devXX:800/test/docs\"";
kwQuery.ResultTypes = ResultType.RelevantResults;
ResultTableCollection results = kwQuery.Execute();
ResultTable relevantResults = results[ResultType.RelevantResults];
dt.Load(relevantResults, LoadOption.OverwriteChanges);
source to share