Created
February 23, 2015 12:34
-
-
Save vgrem/520df74f8251506ca2e9 to your computer and use it in GitHub Desktop.
Demonstrates how to query all search results using SharePoint 2013 Search REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function search(webUrl,queryText,rowLimit,startRow,allResults) | |
{ | |
var allResults = allResults || []; | |
var url = webUrl + "/_api/search/query?querytext='" + queryText + "'&rowlimit=" + rowLimit + "'&startrow=" + startRow; | |
return $.getJSON(url).then(function(data) { | |
var relevantResults = data.PrimaryQueryResult.RelevantResults; | |
allResults = allResults.concat(relevantResults.Table.Rows); | |
if (relevantResults.TotalRows > startRow + relevantResults.RowCount) { | |
return search(webUrl,queryText,rowLimit,startRow+relevantResults.RowCount,allResults); | |
} | |
return allResults; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment