Skip to content

Commit f5d043f

Browse files
authored
Updated pagination for large results set (SharePoint#7020)
Added a CSOM example and made it important to include the brackets when using the sortlist. Otherwise, queries might fail in certain scenarios
1 parent 8dafa5c commit f5d043f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/general-development/pagination-for-large-result-sets.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,18 @@ GET http://{site_url}/_api/search/query?querytext='sharepoint indexdocid>20'&amp
5454
```
5555

5656
And so on for the rest of the pages.
57+
58+
To use the same approach in CSOM, see the following example:
59+
```C#
60+
...
61+
if (startRow == 0) // When issueing the query for first time, we don't have a DocId value yet
62+
keywordQuery.QueryText = "sharepoint";
63+
else // Putting the IndexDocId first and then the 'actual' query matters (in this case searching for the keyword 'sharepoint')
64+
keywordQuery.QueryText = string.Format("IndexDocId > {0} AND (sharepoint)", startRow);
65+
keywordQuery.EnableSorting = true;
66+
keywordQuery.SortList.Add("[DocId]", Microsoft.SharePoint.Client.Search.Query.SortDirection.Ascending);
67+
...
68+
```
69+
70+
> [!NOTE]
71+
> When using the SortList in search queries, the fieldname being used must be enclosed by brackets (e.g. `[DocId]`).

0 commit comments

Comments
 (0)