title: Using the Search API with Sharepoint Foundation 2010 - 0 results
body: <p>I am a sharepoint newbee and am having trouble getting any search results to return using the search API in Sharepoint 2010 Foundation.</p>
  
  <p>Here are the steps I have taken so far.</p>
  
  <ol>
  <li>The Service Sharepoint Foundation Search v4 is running and logged in as Local Service</li>
  <li>Under Team Site - Site Settings - Search and Offline Availability, Indexing Site Content is  enabled.</li>
  <li>Running the PowerShell script Get-SPSearchServiceInstance returns</li>
  </ol>
  
  <p>TypeName      : SharePoint Foundation Search<br>
  Description   : Search index file on the search server<br>
  Id            : 91e01ce1-016e-44e0-a938-035d37613b70<br>
  Server        : SPServer Name=V-SP2010<br>
  Service       : SPSearchService Name=SPSearch4<br>
  IndexLocation : C:\Program Files\Common Files\Microsoft Shared\Web Server Exten
                  sions\14\Data\Applications<br>
  ProxyType     : Default<br>
  Status        : Online  </p>
  
  <ol start="4">
  <li>When I do a search using the search textbox on the team site I get a results as I would expect.</li>
  </ol>
  
  <p>Now, when I try to duplicate the search results using the Search API I either receive an error or 0 results.</p>
  
  <p>Here is some sample code:</p>
  
  <pre><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);
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>Any ideas about what I am doing wrong? </p>