Pnpjs: Using the ISearchQuery interface RowsPerPage property has no effect on the number of results per page

Created on 25 Aug 2020  路  2Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [X] Bug
  • [ ] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [ @pnp/[email protected] ]

Please specify what version(s) of SharePoint you are targeting: [ 16.0.0.20405 ]

Expected / Desired Behavior / Question

Using the ISearchQuery interface to create a query using paging with StartRow, RowLimit and RowsPerPage, setting a value of 10 RowsPerPage returns 10 results per page/query.

Observed Behavior

Using the ISearchQuery interface to create a query using paging with StartRow, RowLimit and RowsPerPage, setting any value for RowsPerPage doesn't have any effect on the number of results returned per page.

Steps to Reproduce

Using the ISearchQuery interface to create a query that uses paging and setting the RowLimit from the property pane and a fixed value of 10 for RowsPerPage, the query returns whatever value is set for RowLimit in the first page of the paginated results and the RowsPerPage value of 10 is ignored.

  private newsArchiveSearch(
    queryText: string,
    rowLimit: number,
    highPrioritySort = false,
    currentPage: number,
    totalPages: number
  ): Promise<INews[]> {
    return new Promise<INews[]>(
      (
        resolve: (news: INews[]) => void,
        reject: (error: any) => void
      ): void => {
        rowLimit = totalPages;

        let startRow = (currentPage - 1) * 10 + 1;

        let query = <SearchQuery>{
          Querytext: queryText,
          StartRow: startRow,
          RowsPerPage: 10,
          RowLimit: rowLimit,
          TrimDuplicates: false,

          SelectProperties: [
            "PictureThumbnailURL",
            "Title",
            "Path",
            "FirstPublishedDate",
            "Description",
            "SPWebUrl",
          ],

          SortList: [
            {
              Property: "FirstPublishedDate",
              Direction: SortDirection.Descending,
            },
          ],
        };
        sp.search(query)
          .then((r: SearchResults) => {
            this.currentResults = r;
            Log(
              LOG_SOURCE,
              `Retrieved ${r.PrimarySearchResults.length} raw results`
            );
            let news = new Array<INews>();
            r.PrimarySearchResults.forEach((result) => {
do something with the results
}
documentation answered question

Most helpful comment

My expectations are that RowsPerPage is a legacy property for the search web part. Please correct me if I'm wrong.
I was always using RowLimit and StartRow in Search API for pagination.

https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee543526(v%3Doffice.15)

image

All 2 comments

My expectations are that RowsPerPage is a legacy property for the search web part. Please correct me if I'm wrong.
I was always using RowLimit and StartRow in Search API for pagination.

https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee543526(v%3Doffice.15)

image

Going to close this as answered. If you have further questions please open a new issue, ref this one, and provide any additional details you can.

Was this page helpful?
0 / 5 - 0 ratings