CloudCannon / pagefind

Static low-bandwidth search at scale
https://pagefind.app
MIT License
3.45k stars 111 forks source link

Allow searching of metadata #532

Open skrysmanski opened 9 months ago

skrysmanski commented 9 months ago

I've noticed that Pagefind doesn't seem to find pages where the search terms just appear in the title - if it's outside data-pagefind-body.

Basically I have pages like this:

<header>
  <h1 data-pagefind-meta="title">PHP Cheat Sheet</h1>
</header>
<article data-pagefind-body>
  ...
</article>

In my example, the words "cheat sheet" don't appear in the actual article but just in the title.

If I now search for "cheat sheet" (with the Default UI), Pagefind doesn't find this page.

My workaround is to also add data-pagefind-body to the <h1> element but in my opinion this shouldn't be necessary.

This problem probably extends to all meta data.

bglw commented 9 months ago

Correct on all counts (that this is currently intended, but isn't desirable). I'm hoping that part of #437 will involve bringing more metadata into the search index, but it needs a little bit of care to support use-cases where other metadata explicitly shouldn't be searchable.

Since this issue captures it more generally, I'll keep both around and track the overall ability to search metadata here 🙂

bglw commented 9 months ago

(Possibly helpful context for why this isn't a simple toggle: Currently the metadata only exists in the final page fragment that is loaded when showing a result. The metadata doesn't exist at the time of querying, so the index itself will need to change to implement this feature)