v2.0.2
Customize the search index
Search is powered by FlexSearch and configured entirely through canopy.yml plus optional front
matter on MDX pages. This guide walks through indexing additional metadata, enabling summaries,
adding annotation text, and splitting results into custom tabs.
Prereq: Start with a working Canopy project and at least one IIIF collection configured.
1. Extend canopy.yml
Add a search block (or edit the existing one) to enable metadata and summary indexing, plus custom
layouts for each record type.
search: results: work: layout: grid result: figure page: layout: list result: article docs: layout: list result: article tabs: order: - work - docs - page index: metadata: enabled: true all: false summary: enabled: true annotations: enabled: true motivation: - commenting - taggingKey ideas:
results.<type>controls layout/markup per record type. Add entries for new types you introduce via front matter (for example,docs).tabs.orderestablishes the tab order in the runtime. Types not listed fall back to the order inresults.index.metadata.allcontrols whether every metadata entry from each manifest is indexed. When it isfalse, Canopy only indexes the labels listed in the top-levelmetadataarray ofcanopy.yml.index.summary.enabledtoggles whether manifest/page summaries become searchable text.index.annotations.enabledwrites a third artifact (search-index-annotations.json) that stores annotation bodies. Setmotivationto the list you care about.
2. Tag MDX pages for search
Front matter controls which MDX pages enter the search index and how they appear in results.
---title: A View of BoondisearchType: docssearchSummary: Explore a print of Boondi from Northwestern University Libraries.referencedManifests: - https://api.dc.library.northwestern.edu/api/v2/works/4bdb5a22-6c7f-498d-8e6e-e49ea9bc4778?as=iiif--- # A View of Boondi ...Fields:
search: false— opt out entirely.searchType— overrides the defaultpagetype (typeworks too;searchTypecomes first). Match this with an entry undersearch.resultsto give the type its own tab/layout.searchSummary— a concise teaser the page's result shows, in place of an excerpt. Its words are searched too, ahead of the page's own.searchSummaryMarkdown— the same teaser with inline Markdown:code, emphasis, strong.description— the teaser when neither is set, as it is the page's<meta name="description">. With none of the three, a result shows the passage around the words searched for.image— an image shown beside the result, and in the header's suggestions: an absolute URL, or a path from the site's root (/images/boondi.jpg).
3. Verify the generated artifacts
Run npm run build (or restart npm run dev) and inspect the files under site/api/:
search-index.json— compact payload used to populate FlexSearch. Inspect it to confirm metadata labels and summaries are present.search-records.json— rich records referenced when rendering the UI.search-index-annotations.json— only written whenannotations.enabledistrue.
If annotation indexing is enabled, the browser runtime fetches the annotations file on demand and merges it into the FlexSearch source before running queries.
4. Custom result templates
Set result: figure or result: article per type (see search.results above). Then override the
corresponding MDX partial under content/search/ to adjust the markup:
_result-figure.mdx_result-article.mdx
Both receive record, query, and runtime helpers so you can render badges, metadata, or excerpts.
If these files are missing, Canopy falls back to its defaults.
5. Troubleshooting
- Missing metadata values in the index — ensure the exact label appears in
canopy.yml → metadata(for facet generation and selective metadata indexing). Setsearch.index.metadata.all: trueto include every metadata entry regardless of the list. - Tabs in the wrong order — confirm every type is listed in
tabs.order. Anything omitted falls back to the declaration order underresults. - MDX page not indexed — remove
search: false(if present) and make sure the file is not in acontent/search/directory (that folder is reserved for templates).