Polaris Astro documentation

Search

How site search works in Polaris, what it finds, how to leave a page out, and the difference between site search and the trip search form.

Polaris has two kinds of search. They do different jobs.

What it does Where
Site search Finds words on any page, such as a trip, a stay or a journal article. The search button in the header
Trip search form Sends the visitor to a filtered list of trips or stays by place, month and travellers. The hero (search variant) and search blocks

This page is about site search. The trip search form is set up with the search block and the finder block. See Pages and blocks.

How site search works

Site search uses Pagefind. It needs no account or server. The search index is built when you run npm run build: the postbuild step runs pagefind --site dist and writes the index into dist/pagefind/. The index is loaded only when a visitor opens the search panel, so it adds no weight to your pages.

The search button is in the header. It opens a panel with a search box and up to eight results, each with a photo, a label (Page, Destination, Trip, Stay or Journal), the title and a short excerpt. Pressing / anywhere outside a form field opens the panel, and Esc closes it.

Trying it

Search is not available in npm run dev, because there is no index yet. The panel says so. To try it:

npm run build
npm run preview

Then open http://localhost:4321 and search.

What is searchable

  • Trip, stay, destination and journal pages.
  • Content pages, such as About and FAQ.

Blocks that only list other pages are skipped, so a result quotes the page itself and not every card on it. These blocks are left out of the index: trips, stays, destinations, journal, finder, cta, search, reviews, hosts, partners and gallery.

Leaving a page out

Add search: false to the page’s front matter:

---
title: All trips
search: false
sections:
  # ...
---

The demo does this on its three home pages and its list pages (/trips/, /stays/, /camping/, /destinations/, /journal/) and on /enquire/, because they only list other pages or hold a form. A page with noindex: true is left out of search too. The block library and style guide are demo pages and not part of your content.

Changing the words

The placeholder text, the “no results” message and the other words in the panel are in src/i18n/ui.ts, in the entries that start with search.. The labels shown on results are the search.kind. entries.

Other hosts

Search needs the pagefind folder that npm run build creates inside dist/. If you upload dist by hand, upload that folder too. See Deploying.