Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

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

share|improve this answer
    
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 –  Ismail Durgut PhD Jul 17 '12 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 Jul 17 '12 at 17:18
add comment

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

share|improve this answer
    
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 Jul 17 '12 at 14:49
add comment

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() ")

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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