CloudCannon / pagefind

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

Allow "Filters" in PagefindUI? #47

Open hithismani opened 2 years ago

hithismani commented 2 years ago

Hey!

I can't begin to say how helpful pagefind has been for our projects, incredibly grateful that this was made possible :)

My suggestion or question is really simple! Is there a way I can enable the "filters" in PagefindUI() options? I want to limit the search responses to the current section only. I.e when a user searches "Events" they shouldn't be shown blogs.

Basically allowing us to extend pagefind options into the PagefindUI() configuration. Something like:

new PagefindUI({ 
            element: "#search",
            filters: {
                Type: ["Events"],
            }
        });

I'd love to know if this is possible!

bglw commented 2 years ago

Yes that's certainly possible, I'll look at adding that 🙂

How do you want the UI to then handle that filter? Options:

  1. The Type filter group is shown in the search UI. Events is pre-selected
  2. The Type filter group is shown in the search UI. Events is forced on and not shown in the list of options.
  3. The Type filter group is hidden altogether in the search UI.
hithismani commented 2 years ago

Fascinating approaches!

I'd say that most ideal, is:

bglw commented 2 years ago

Thanks, I think that sounds like a good approach 🙂 I'll look at this in the near future

rauschma commented 2 years ago

Maybe general faceted navigation would make sense for Pagefind.

You can see a (very crude) implementation here: https://2ality.com/archive.html

In this case, the facets are: Year, Month, Tag.

bglw commented 2 years ago

@rauschma as far as I can tell the underlying structure of Pagefind's filters supports a faceted navigation approach yes? So this would only impact the UI library.

I think for this kind of change I would really like to have a showcase of Pagefind UI widgets that can be used in place of the builtin widget, which saves the default from having to cater to every use case (and could also provide framework-specific components)

rauschma commented 2 years ago

@bglw Makes sense. Thanks for clarifying!