CloudCannon / pagefind

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

Allow settings for filter groups in `PagefindUI` #595

Open nhoizey opened 2 months ago

nhoizey commented 2 months ago

I already opened multiple issues for improvements of filter groups in PagefindUI:

Here's an attempt at setting these features in the PagefindUI initialization:

const search_ui = new PagefindUI({
  filterGroups: {
    "group 1": {
      order: 2,
      sort: "alphanum",
      logic: "OR"
    },
    "group 2": {
      order: 1,
      sort: "results",
      logic: "AND"
    }
  }
});

filterGroups takes an object with an element per filter group where we want to define settings different from the default ones:

setting default values description
order undefined number Sets the order of the group in the list of filter groups. Groups without this setting are listed after the ones with it, in the same alphanumerical order as currently.
sort alphanum alphanum, results Sets the order of filter values in this group. results sorts the filter values by decreasing number of results with this value.
logic AND AND, OR Sets the logic between values from the same group.