I'm currently working on creating a custom search page built from scratch, and thus I'm trying to query our site for keywords.
I have set-up the SharePoint Foundation Search on Central Admin and I can see the search works fine when I use the default search page that SharePoint comes with.
But when I try query the results in C# using KeywordQuery I get no results back and when I try and use the FullTextSqlQuery I get an error "Scope in your query does not exist."
Here is a sample of my code for both the keywordQuery and the FullTextSQLQuery
Microsoft.SharePoint.Search.Query.KeywordQuery myQuery = new Microsoft.SharePoint.Search.Query.KeywordQuery(site);
myQuery.QueryText = tag;
try
{
ResultTableCollection queryResults = myQuery.Execute();
if (queryResults.Count > 0)
{
DataTable retResults = new DataTable();
using (ResultTable relevantResults = queryResults[ResultType.RelevantResults])
retResults.Load(relevantResults, LoadOption.OverwriteChanges);
FullTextSqlQuery myQuery = new FullTextSqlQuery(site)
{
QueryText = String.Format("SELECT Title, SiteName, Path FROM Scope() WHERE \"scope\"='All Sites' AND CONTAINS('\"{0}\"')", tag),
//QueryText = String.Format("SELECT Title, SiteName, Path FROM Scope()", searchPhrase),
TrimDuplicates = true,
StartRow = 0,
RowLimit = 200,
ResultTypes = ResultType.RelevantResults
//IgnoreAllNoiseQuery = false
};
ResultTableCollection queryResults = myQuery.Execute();
if (queryResults.Count > 0)
{
DataTable retResults = new DataTable();
using (ResultTable relevantResults = queryResults[ResultType.RelevantResults])
retResults.Load(relevantResults, LoadOption.OverwriteChanges);
Can you guys please help me figure out what the issue is?
Edit: issue fixed, for the FullTextSqlQuery it turned out my QueryText was not right.
This is the right format QueryText = String.Format("SELECT Title, Path FROM Scope() WHERE CONTAINS('{0}')", tag),