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.
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.
Paging a search
A search pages with page (from 1) and limit (results per page):
limitis 1 to 50, and 10 when you leave it out. Map pins (view=map) come back up to 200 on one page.pagegoes up to 40, andpagetimeslimitcan be at most 2,000. A deeper page answers 400page_depth_exceeded. Narrow the search instead: a visitor never needs result 2,001, and a sitemap uses the listing ids feed.data.totalis the exact number of matches anddata.pagesis how many pages you can link to, already capped by those limits. Usedata.pages, nottotal / 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"import { createClient } from "@ruuster/idx";
const idx = createClient({ secretKey: process.env.IDX_SECRET_KEY });
const r = await idx.search({
zip: "30308",
sort: "price_desc",
page: 2,
limit: 24,
});
if (!r.ok) throw new Error(`${r.error.code}: ${r.error.message}`);
console.log(r.data);import os
import requests
res = requests.get(
"https://idx.ruuster.com/v1/listings",
params={
"zip": "30308",
"sort": "price_desc",
"page": "2",
"limit": "24",
},
headers={"Authorization": "Bearer " + os.environ["IDX_SECRET_KEY"]},
timeout=30,
)
body = res.json()
if not body["ok"]:
raise RuntimeError(body["error"]["code"] + ": " + body["error"]["message"])
print(body["data"])<?php
$query = http_build_query([
'zip' => '30308',
'sort' => 'price_desc',
'page' => '2',
'limit' => '24',
], '', '&', PHP_QUERY_RFC3986);
$ch = curl_init('https://idx.ruuster.com/v1/listings' . '?' . $query);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('IDX_SECRET_KEY')],
CURLOPT_TIMEOUT => 30,
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!$body['ok']) {
throw new RuntimeException($body['error']['code'] . ': ' . $body['error']['message']);
}
print_r($body['data']);Page links that search engines follow
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.
<!--
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&bedsMin=3" rel="prev">Previous page</a>
<ul class="rw-pagination__list">
<li><a class="rw-pagination__page" href="/search?city=Powder+Springs&bedsMin=3" aria-label="Page 1">1</a></li>
<li><a class="rw-pagination__page rw-pagination__page--current" href="/search?city=Powder+Springs&bedsMin=3&page=2" aria-current="page" aria-label="Page 2">2</a></li>
<li><a class="rw-pagination__page" href="/search?city=Powder+Springs&bedsMin=3&page=3" aria-label="Page 3">3</a></li>
<li><a class="rw-pagination__page" href="/search?city=Powder+Springs&bedsMin=3&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&bedsMin=3&page=7" aria-label="Page 7">7</a></li>
</ul>
<a class="rw-pagination__step" href="/search?city=Powder+Springs&bedsMin=3&page=3" rel="next">Next page</a>
</nav>import { Pagination } from "@ruuster/idx-recipes";
<Pagination page={2} pages={7} basePath={basePath} searchParams={searchParams} />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.nextCursoris 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.nextCursoris always set; call again at once whilehasMoreis 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.