5

Problem

I have a java application which till now used SP2010 with SQL Syntax for Search queries. Everything worked fine with the Query Webservice until I upgraded to SP2013.

Now, I've come to know that only FQL and KQL and REST will be supported in SP2013.

SP2013 has removed support from SQL Syntax.

I also found that FQL has less features than KQL, so the obvious choice is to use KQL now.

Help needed

I would like to know how to migrate the following code to work for SP2013.

What worked till now

Code that works for SP2010 :-

  1. I generate QueryService Stub from the _vti_bin\search.asmx?wsdl.
  2. Then I construct an XML,

     public static String queryText(String keyword, String contextualScope, String customScope) {
        int startAt = 1;
        int count = 10;
        boolean trimDuplicates = false;
        String sortQuery = null;
        String query = 
              "<QueryPacket xmlns='urn:Microsoft.Search.Query'>" +
                    "<Query>" +
                        "<SupportedFormats>" +
                            "<Format>urn:Microsoft.Search.Response.Document.Document</Format>" +
                        "</SupportedFormats>" +
                        "<Context>" +
                            "<QueryText language='en-US' type='MSSQLFT'>" +
                                "select title, path, Author, sitename, isdocument from scope() where freetext('" + keyword + "') ";
                                if(contextualScope!=null && !contextualScope.trim().equals(""))
                                query += " and \"site\"='" + contextualScope + "'";     
                                if(customScope!=null && !customScope.trim().equals(""))
                                query += " and \"scope\"='" + customScope + "'";
                                query += "</QueryText>" +
                        "</Context>" +
                        "<Range>" +
                            "<StartAt>" +
                                startAt +
                            "</StartAt>" +
                            "<Count>" +
                                count +
                            "</Count>" +
                        "</Range>";
                        if(sortQuery != null)
                            query += sortQuery;
                        query += "<TrimDuplicates>" +
                        trimDuplicates + 
                        "</TrimDuplicates>" +
                    "</Query>" +
                "</QueryPacket>";
        return query;
        }
    
  3. After that I run the following command to perform the search operation,

    QueryServiceStub.Query q = new QueryServiceStub.Query();
    
    q.setQueryXml(queryText(...));
    
    return qsStub.Query(q); 
    
  4. For SP 2010 the above stuff works fine. But for SP 2013 it throws the following error,

w3wp.exe (0x26C8) 0x375C SharePoint Server Search Query dn6x High Exception caught in QueryService.Query method. Exception message: Specified method is not supported.. Stack: at Microsoft.Office.Server.Search.Query.FullTextSqlQuery.PreQueryExecute() at Microsoft.Office.Server.Search.Query.Query.ExecuteQuery() at Microsoft.Office.Server.Search.Query.Query.Execute() at Microsoft.Office.Server.Search.Query.QueryService.DoQuery(QueryMethod queryMethod, String queryXml, String& domain, String& queryId, Int32& startAt, Boolean& fStandardResults, QuerySuggestionResults& querySuggestions) at Microsoft.Office.Server.Search.Query.QueryService.Query(String queryXml). 30971d9c-a7e0-c04d-ba15-7bf4d49fb253

Please let me know if I'm not clear in my question. Even some pointers or example or guidance will be helpful.

2 Answers 2

3

Finally, I learned how to use KQL and it's more neat than SQL here.

public static String queryText(String keyword, String contextualScope, String customScope) {
    int startAt = 1;
    int count = 10;
    boolean trimDuplicates = false;
    String sortQuery = null;
    String query = 
          "<QueryPacket xmlns='urn:Microsoft.Search.Query'>" +
                "<Query>" +
                   "<SupportedFormats>" +
                                    "<Format>urn:Microsoft.Search.Response.Document.Document</Format>" +
                                "</SupportedFormats>" +
                                "<Context>" +
                                    "<QueryText language='en-US' type='STRING'>" +                                      
                                        keyword +
                                    "</QueryText>" +
                                "</Context>" +
                                "<Range>" +
                                    "<StartAt>" +
                                       startAt +
                                    "</StartAt>" +
                                    "<Count>" +
                                        count +
                                    "</Count>" +
                                "</Range>" +
                                 "<Properties>" +
                                    "<Property name=\"Title\"/>" +
                                    "<Property name=\"Path\"/>" +
                                    "<Property name=\"Author\"/>" +
                                    "<Property name=\"SitePath\"/>" +
                                    "<Property name=\"IsDocument\"/>" +
                                "</Properties>" +                                   
                                "<TrimDuplicates>" +
                                    trimDuplicates + 
                                "</TrimDuplicates>" +       
                "</Query>" +
            "</QueryPacket>";
    return query;
    }

Now since my application was working fine with 2010 and 2007, I tried the above KQL query with them but it failed with Not SUPPORTED error.

So, I had to find a way out to determine which Sharepoint server I was hitting before firing the search query.

The only way I could find was to hit the following url to determine the version of Sharepoint server. When you hit http://SP_hostname/_vti_pvt/service.cnf it returns the following,

vti_encoding:SR|utf8-nl 
vti_extenderversion:SR|15.0.0.4420

The vti_extenderversion,

  • For SP2013 starts with SR|15
  • For SP2010 starts with SR|14
  • For SP2007 starts with SR|12
0

It seems you are creating the custom scopes. Can you make sure that custom scopes are created? If scopes are not created then create it and perform a full crawl again.

2
  • how is this specifically related to custom scope? I want a conversion from SQL to KQL and that too in Java.And my SQL search, crawl and all works fine on 2010 and 2007 SPs. The crawl works fine on SP 2013, the documents get indexed properly as I can see it from the UI. It only fails on API front .
    – Arham
    May 28, 2013 at 4:49
  • Please check my answer below. It works like a charm. Now I'm curios to know the equivalent in FQL aka Fast Query Language. Please share here if you know how to convert the same into an FQL or create a new post detailing the same. :)
    – Arham
    Jun 2, 2013 at 10:50

Your Answer

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

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