Using the Search API with Sharepoint Foundation 2010 - 0 results
- by MB
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 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 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?