0

I'm trying to make a search request on the "/_vti_bin/search.asmx" page in Sharepoint Online.

I use the QueryEx method to post the request.

Here is the request:

        var xmlQuery = "<QueryPacket xmlns=\"urn:Microsoft.Search.Query\">";
        xmlQuery += "<Query>";
        xmlQuery += "<SupportedFormats><Format>urn:Microsoft.Search.Response.Document.Document</Format></SupportedFormats>";
        xmlQuery += "<Context><QueryText type=\"STRING\" >" + keyword + "</QueryText></Context>";
        xmlQuery += "<SortByProperties><SortByProperty name=\"Rank\" direction=\"Descending\" order=\"1\"/></SortByProperties>";
        xmlQuery += "<Properties>";
        xmlQuery += "<Property name=\"SiteTitle\"/>";
        xmlQuery += "<Property name=\"Title\"/>";
        xmlQuery += "<Property name=\"Path\"/>";
        xmlQuery += "</Properties>";
        xmlQuery += "<Range><StartAt>" + startAt + "</StartAt><Count>" + count + "</Count></Range>";
        xmlQuery += "<EnableStemming>" + (enableStemming ? "true" : "false") + "</EnableStemming>";
        xmlQuery += "<TrimDuplicates>" + (trimDuplicates ? "true" : "false") + "</TrimDuplicates>";
        xmlQuery += "<IgnoreAllNoiseQuery>" + (ignoreAllNoiseQuery ? "true" : "false") + "</IgnoreAllNoiseQuery>";
        xmlQuery += "<ImplicitAndBehavior>" + (impliciteAndBehavior ? "true" : "false") + "</ImplicitAndBehavior>";
        xmlQuery += "<IncludeRelevanceResults>" + (includeRelevanceResults ? "true" : "false") + "</IncludeRelevanceResults>";
        xmlQuery += "<IncludeSpecialTermResults>" + (includeSpecialTermResults ? "true" : "false") + "</IncludeSpecialTermResults>";
        xmlQuery += "<IncludeHighConfidenceResults>" + (includeHighConfidenceResults ? "true" : "false") + "</IncludeHighConfidenceResults>";
        xmlQuery += "</Query>";
        xmlQuery += "</QueryPacket>";

It returns some results, but the results come from all over the Sharepoint, not only from the site where I do my search. Is there any way to limit the scope of the search request to have only results from the site ?

Sorry for my bad english :/

1
  • 1
    Rather than use the Search.asmx you should use REST. Commented Jul 30, 2015 at 17:05

1 Answer 1

1

You should be using REST with SharePoint online. The end point is formatted like this:

[site]/_api/search/query?querytext='query'

It is far easier to use and requests can be made from many platforms.

The documentation is here: https://msdn.microsoft.com/en-us/library/office/jj163876.aspx

You can either create a Result Source and use the SourceId attribute or you can just add the path to your query. (I prefer the result source myself.)

0

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.