First, you have to add the following references:

  • Microsoft.Sharepoint
  • Microsoft.Sharepoint.Search

Second:

DataTable resultsDataTable = new DataTable();

 

using (SPSite site = new SPSite("http://server"))

{

FullTextSqlQuery query = new FullTextSqlQuery(site);

query.QueryText = queryText;

query.ResultTypes = ResultType.RelevantResults;

 

ResultTableCollection resultTables = query.Execute();


if (resultTables.Count > 0)

{

ResultTable relevantResults = resultTables[ResulType.RelevantResults];

resultsDataTable.Load(relevantResults, LoadOption.OverwriteChanges);

}

}

 

return resultsDataTable;

 

In WSS the only ResultType possible is RelevantResults but you have to define it with the following statement:

query.ResultTypes = ResultType.RelevantResults;

 

If you don't do that the ResultTableCollection doesn't return any ResultTable.

You can control the properties returned in the SELECT statement:

string queryText = "SELECT rank, workid, title, path, author, contenttype from Scope()";

 

If you want you can page the results:

int pageSize = 3;

int page = 0;

 


 

query.StartRow = page * pageSize;

query.RowLimit = pageSize;

 

To sort the results you use the ORDER BY statment:

string queryText = "SELECT rank, workid, title, path, author, contenttype from Scope() ORDER BY rank ASC, title DESC";

 

I don't know why but it seems that only the first sort column works. I tried to change the direction and also the property of the second sort column but the results were always ordered the same way.

 

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here