1

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),

3 Answers 3

1

Here is a link about an issue with the managed property SiteName. This might be the isse, have you tried to query for just Title?

http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/90244999-2a5d-43fa-9915-c44f2bd2d1a0/

Also, CONTAINS('\"{0}\"')" here are you trying to search for "tag" or tag. Single quotes are enough, here is the link for syntax:
http://msdn.microsoft.com/en-us/library/ms513993.aspx

2
  • Also, CONTAINS('\"{0}\"')" here are you trying to search for "tag" or tag. Single quotes are enough, here is the link for syntax: msdn.microsoft.com/en-us/library/ms513993.aspx Commented Jul 17, 2012 at 16:31
  • Thanks, your answer lead me in the right direction. The correct QueryText is QueryText = String.Format("SELECT Title, Path FROM Scope() WHERE CONTAINS('{0}')", tag),
    – Caesar
    Commented Jul 17, 2012 at 17:18
1

Actually the correct managed property that you need to use in your query is called: 'SiteTitle' 'ows_SiteName' is the crawled property.

So your query will look something like:

QueryText = String.Format("SELECT Title, SiteTitle, Path FROM Scope() ")

0

I know I am not directly helping but this site may help. http://sharepointsearchserv.codeplex.com/

1
  • I have taken a look at that before, but I couldn't figure out how to get it to work. Is there any tutorial on how to use it?
    – Caesar
    Commented Jul 17, 2012 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.