I am a sharepoint newbee and am having trouble getting any search results to return using the search API in Sharepoint 2010 Foundation.
Here are the steps I have taken so far.
- The Service Sharepoint Foundation Search v4 is running and logged in as Local Service
- Under Team Site - Site Settings - Search and Offline Availability, Indexing Site Content is enabled.
- Running the PowerShell script Get-SPSearchServiceInstance returns
TypeName : SharePoint Foundation Search
Description : Search 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 sions\14\Data\Applications ProxyType : Default Status : Online- When I do a search using the search textbox on the team site I get a results as I would expect.
Now, when I try to duplicate the search results using the Search API I either receive an error or 0 results.
Here is some sample c开发者_如何学运维ode:
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 the scope is set to All Sites I retrieve an error about the search scope not being available. Other search just return 0 results.
Any ideas about what I am doing wrong?
This is the workaround we came up with.
We did not get the foundation search to work as we had hoped. We will review it again once the RTM version of Sharepoint Foundation is released.
We installed Search Server Express 2010 beta. This allowed us to use the office server namespaces and the corresponding classes. This worked as expected and we were able to programmatically search against Sharepoint Foundation.
I also never got results by using FullTextSqlQuery on Foundation Search but perhaps 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);
精彩评论