Add an opt-in option to lowercase filter values

Filter values that only differ in case, like `Mint` and `mint`, came
through as separate values. The new `--lowercase-filters` option
(`lowercase_filters`, `PAGEFIND_LOWERCASE_FILTERS`, and
`lowercaseFilters` / `lowercase_filters` in the Node and Python
wrappers) lowercases filter values when indexing and merges values on
a page that become equal. Filter names are left as they are. Off by
default.

Fixes #737
This commit is contained in:
dualfroz committed 2026-10-03 01:43:17 +02:00
1 parent 1308f3c1bb
commit 3a1d31147a
12 files changed
+176

No files matched your search

@@ -0,0 +1,51 @@
name: Filtering > Filter values can be lowercased
steps:
- step: I have the environment variable "PAGEFIND_SITE" set to "public"
- step: I have a "public/index.html" file with the content {html}
html: >-
<!DOCTYPE html><html lang="en"><head></head><body><p
data-results>Nothing</p></body></html>
- step: I have a "public/cheeka/index.html" file with the content {html}
html: >-
<!DOCTYPE html><html lang="en"><head></head><body><span
data-pagefind-filter="color">Black</span>
<span data-pagefind-filter="color">White</span>
<span data-pagefind-filter="color">white</span>
<h1>Cat</h1></body></html>
- step: I have a "public/theodore/index.html" file with the content {html}
html: >-
<!DOCTYPE html><html lang="en"><head></head><body><span
data-pagefind-filter="color">WHITE</span>
<h1>Cat</h1></body></html>
- macro: I run Pagefind with "--lowercase-filters"
- step: stdout should contain "Running Pagefind"
- step: I serve the directory "public"
- step: In my browser, I load "/"
- step: In my browser, I evaluate {js}
js: |-
let pagefind = await import("/pagefind/pagefind.js");
let filters = await pagefind.filters();
let strings = Object.entries(filters).map(([filter, values]) => {
values = Object.entries(values).map(([value, count]) => {
return `${value}(${count})`;
})
return `${filter}:[${values.join(", ")}]`;
});
let search = await pagefind.search("Cat", { filters: { color: "white" } });
let data = await Promise.all(search.results.map(result => result.data()));
document.querySelector('[data-results]').innerText = strings.join(' ')
+ ' ' + data.map(d => d.url).sort().join(', ');
- step: In my browser, the console should be empty
- step: In my browser, I evaluate {js}
js: >-
let val = await toolproof.querySelector("[data-results]");
toolproof.assert_eq(val.innerHTML, `color:[black(1), white(2)]
/cheeka/, /theodore/`);
@@ -0,0 +1,39 @@
name: Node API Base Tests > Pagefind lowercaseFilters config
platforms:
- linux
- mac
steps:
- ref: ./background.toolproof.yml
- step: I have a "public/index.js" file with the content {js}
js: |2-
import * as pagefind from "pagefind";
const run = async () => {
const { index } = await pagefind.createIndex({
lowercaseFilters: true,
});
await index.addHTMLFile({sourcePath: "page_a/index.html", content: "<html lang='en'><body><h1 data-pagefind-filter='color:White'>Cat</h1></body></html>"});
await index.addCustomRecord({
url: "/page_b/",
content: "Cat",
language: "en",
filters: { color: ["WHITE", "Black"] },
});
await index.writeFiles();
console.log(`Successfully wrote files`);
}
run();
- macro: I run Pagefind Node as "index.js" in "public"
- step: stdout should contain "Successfully wrote files"
- step: The file "public/pagefind/pagefind.js" should not be empty
- step: I serve the directory "public"
- step: In my browser, I load "/"
- step: In my browser, I evaluate {js}
js: |-
let pagefind = await import("/pagefind/pagefind.js");
let filters = await pagefind.filters();
toolproof.assert_eq(JSON.stringify(filters), `{"color":{"black":1,"white":2}}`);
- step: In my browser, the console should be empty