Menu · Guides
Guides

Sorting and paging

Sort results, page through them with page and limit, keep the order stable across pages, and page the feeds and lists that use a cursor.

View as Markdownopenapi.json

Sorting

sort picks the order of a search:

Value Order
recommended The default: the order Ruuster's own search shows
featured Featured listings first
price_reduced Recent price changes first
oldest Longest on the market first
price_desc, price_asc Highest or lowest price first
beds_desc, baths_desc Most bedrooms or bathrooms first
sqft_desc, lot_desc Largest home or lot first
close_date_desc Most recently sold first, for sold searches
newest First on the market most recently first (a future date counts as today; listings without one come last)

Combining pages. Listings change during the day, so when you combine pages from separate calls, keep each listing once by its id.

A search pages with page (from 1) and limit (results per page):

  • limit is 1 to 50, and 10 when you leave it out. Map pins (view=map) come back up to 200 on one page.
  • page goes up to 40, and page times limit can be at most 2,000. A deeper page answers 400 page_depth_exceeded. Narrow the search instead: a visitor never needs result 2,001, and a sitemap uses the listing ids feed.
  • data.total is the exact number of matches and data.pages is how many pages you can link to, already capped by those limits. Use data.pages, not total / limit, for your page links.
curl -s -G "https://idx.ruuster.com/v1/listings" \
  --data-urlencode zip=30308 \
  --data-urlencode sort=price_desc \
  --data-urlencode page=2 \
  --data-urlencode limit=24 \
  -H "Authorization: Bearer $IDX_SECRET_KEY"

Put the page number in the URL, as in /neighborhoods/midtown?page=2, and render each page link as a plain <a href>. Send your page's own URL as pageHref (without the page number): the answer's head.canonical is then that URL on page 1 and that URL with ?page=N from page 2 on, so every page canonicals to itself. The Pagination recipe component builds the links, keeps your other query parameters, leaves ?page off page 1 and marks the previous and next links.

Live preview
The pagination from the search page recipe.
<!--
  Page links (page 2 of 7).
  From the React component Pagination. Generated by npm run idx:recipes-static from @ruuster/idx-recipes. Do not edit it by hand.

  Fill each value from:
  .rw-pagination__page[href]: your page's path with the current query, plus page=N; page 1 has no page parameter
  .rw-pagination__page--current: the current page (meta.page.page), with aria-current="page"
  the page numbers: the first and last pages, and two pages on each side of the current one, with an li.rw-pagination__gap (…) where pages are skipped; meta.page.pages is the last page
  .rw-pagination__step[rel=prev] and [rel=next]: the previous and next pages; leave Previous out on page 1 and Next out on the last page. Print nothing when there is one page
  Every data-rw-* attribute is a hook for ruuster-idx.js; see ../HOOKS.md.
-->
<nav class="rw-recipes rw-pagination" aria-label="Pages of results">
  <a class="rw-pagination__step" href="/search?city=Powder+Springs&amp;bedsMin=3" rel="prev">Previous page</a>
  <ul class="rw-pagination__list">
    <li><a class="rw-pagination__page" href="/search?city=Powder+Springs&amp;bedsMin=3" aria-label="Page 1">1</a></li>
    <li><a class="rw-pagination__page rw-pagination__page--current" href="/search?city=Powder+Springs&amp;bedsMin=3&amp;page=2" aria-current="page" aria-label="Page 2">2</a></li>
    <li><a class="rw-pagination__page" href="/search?city=Powder+Springs&amp;bedsMin=3&amp;page=3" aria-label="Page 3">3</a></li>
    <li><a class="rw-pagination__page" href="/search?city=Powder+Springs&amp;bedsMin=3&amp;page=4" aria-label="Page 4">4</a></li>
    <li class="rw-pagination__gap" aria-hidden="true">…</li>
    <li><a class="rw-pagination__page" href="/search?city=Powder+Springs&amp;bedsMin=3&amp;page=7" aria-label="Page 7">7</a></li>
  </ul>
  <a class="rw-pagination__step" href="/search?city=Powder+Springs&amp;bedsMin=3&amp;page=3" rel="next">Next page</a>
</nav>

Don't fetch pages in parallel

Fetch one page at a time, when a visitor asks for it. Keep at most four calls in flight per key, and never prefetch pages ahead of the visitor: it spends units and rate limit on pages nobody sees.

Feeds and lists that use a cursor

Three endpoints page with a cursor instead of a page number. Each answer carries nextCursor; send it back as cursor for the next page.

  • GET /v1/listings/ids (secret key): every listing in your boards, for sitemaps. nextCursor is null at the end. A cursor is tied to your boards: when they change, the API refuses the cursor and you start the walk again.
  • GET /v1/changes (secret key): what changed since a time. nextCursor is always set; call again at once while hasMore is true, and later when it is false. A cursor is valid for seven days.
  • GET /v1/collections: your saved collections.

Keeping pages fresh shows the feeds in use.