Faceted search and the inclusion of tighter and tighter filtering helps narrow down the number of documents returned from Azure Search.  However, sometimes the amount of data is too large to load on one page.  In cases like this, Azure Search allows for paging so that you can allow you user to walk through pages of defined results sizes.  Paging can be handled very simply using Azure Search through the BlackBarLabs.Search.Azure library through the use of three search constructs, count, top, and skip.

You may implement paging server-side or client-side.  In our example, I will page through results returned from facet searches.

To begin, we will need to add Skip and Count properties to our AirportSearch model, as shown here:

Then, we will need to utilize the Skip parameter in our call to search and return Top, Skip, and Count in our results so that we can iterate on them as shown in this snippet from AirportController:

Finally, since we will control paging from the client, we will add code to our razor file to manage paging.  Since we are only concerned with paging faceted searches, we will add Top and Skip to our fields set on our AirportSearch model.  You can see here where those are added:

Bear in mind that a page size const pageSize and currentPage are set here.  That code is at the top of the file:

Finally, we will add code to the bottom of of the grid to display “Previous” and “Next” links with our page information.  This code makes paging work by continually updating the Skip field to move forward or backwards 10 items at a time.  There is some code here, also, to make sure we don’t jump out of range:

With the models, controller, and view in place, we can now run our sample.  When you select a facet, you can see that the paging information is shown at the bottom of the results grid:

P5-0-ResultsWithPaging

As we continually click Next, our results set updates and the paging information updates, too:

P5-1-Next

As you can see, paging with Azure Search is as simple as managing the skip parameter sent with your search query.