<div id='codeeditor1-template'>
<script>
function loadSearch (siteUrl, soapEnv, callback, errorcallback, completecallback) {
var url = siteUrl + "/_vti_bin/search.asmx";
$.ajax({
async: true,
url: url,
type: "POST",
dataType: "xml",
data: soapEnv,
contentType: "text/xml; charset=\"utf-8\"",
complete: function (data) {
if (callback)
callback(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (errorcallback)
errorcallback(XMLHttpRequest, textStatus, errorThrown);
},
success: function (XMLHttpRequest, textStatus, errorThrown) {
if (completecallback)
completecallback(XMLHttpRequest, textStatus, errorThrown);
}
});
};
var siteUrl = "https://testsite.sharepoint.com";
var scopeName = "DocumentsScope";
var packet = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><QueryEx xmlns='http://microsoft.com/webservices/OfficeServer/QueryService'><queryXml><![CDATA[<QueryPacket xmlns='urn:Microsoft.Search.Query'><Query><TrimDuplicates>false</TrimDuplicates><Context><QueryText language='en-US' type='STRING'>() AND ANY(*) (IsDocument=True) (scope:" + scopeName + ")</QueryText></Context><Range><StartAt>1</StartAt><Count>10000</Count></Range><Properties><Property name='Title'></Property><Property name='Filename'></Property><Property name='Path'></Property><Property name='LastModifiedTime'></Property></Properties></Query></QueryPacket>]]></queryXml></QueryEx></soap:Body></soap:Envelope>";
loadSearch(siteUrl, packet, function (data) {
if (data.statusText == "OK")
{
var responseXml = $(data.responseText.replace(/<xs:/gi, "<").replace(/<\/xs:/gi, "<\/").replace(/<soap:/gi, "<").replace(/<\/soap:/gi, "<\/").replace(/ msprop:/gi, " "));
var totalRows = responseXml.find("element[name='RelevantResults']").attr("TotalRows");
console.log(totalRows)
}
}, function (XMLHttpRequest, textStatus, errorThrown) {
}, function (XMLHttpRequest, textStatus, errorThrown) {
});
</script>
</div>
The following code is an example of how to make query with search webservices
CODE