diff --git a/docs/content/docs/multisite.md b/docs/content/docs/multisite.md index 45e6c2be..e94d9f4d 100644 --- a/docs/content/docs/multisite.md +++ b/docs/content/docs/multisite.md @@ -64,7 +64,7 @@ Pagefind options can be passed to the additional index as a second argument: // Running on blog.example.com const pagefind = await import("/_pagefind/pagefind.js"); -+await pagefind.options({/* ... options for the blog.example.com index */}) ++await pagefind.options({/* ... options for the blog.example.com index */}); await pagefind.mergeIndex( "https://docs.example.com/_pagefind", + {/* ... options for the docs.example.com index */} @@ -74,23 +74,56 @@ await pagefind.mergeIndex( ## Changing the weighting of individual indexes -When searching across multiple sites you may want to rank each index higher or lower than the others. This can be achieved by passing an `indexWeight` option: +When searching across multiple sites you may want to rank each index higher or lower than the others. This can be achieved by passing an `indexWeight` option for each index: {{< diffcode >}} ```js // UI: new PagefindUI({ element: "#search", ++ indexWeight: 2, mergeIndex: [{ bundlePath: "https://docs.example.com/_pagefind", -+ indexWeight: 2 ++ indexWeight: 0.5 }] }) // JS API: const pagefind = await import("/_pagefind/pagefind.js"); ++await pagefind.options({ indexWeight: 2 }); await pagefind.mergeIndex("https://docs.example.com/_pagefind", { -+ indexWeight: 2 ++ indexWeight: 0.5 +}); +``` +{{< /diffcode >}} + +## Filtering results by index + +When searching across multiple sites you may want to filter to each index, without having to tag every page on each site with the filter. This can be achieved with the `mergeFilter` option on each index: + +{{< diffcode >}} +```js +// UI: +new PagefindUI({ + element: "#search", ++ mergeFilter: { ++ resource: "Blog" ++ }, + mergeIndex: [{ + bundlePath: "https://docs.example.com/_pagefind", ++ mergeFilter: { ++ resource: "Documentation" ++ } + }] +}) + +// JS API: +const pagefind = await import("/_pagefind/pagefind.js"); ++await pagefind.options({ mergeFilter: { resource: "Blog" } }); +await pagefind.mergeIndex("https://docs.example.com/_pagefind", { ++ mergeFilter: { ++ resource: "Documentation" ++ } }); ``` {{< /diffcode >}} diff --git a/docs/content/docs/search-config.md b/docs/content/docs/search-config.md index bfe34ca5..2fff49dd 100644 --- a/docs/content/docs/search-config.md +++ b/docs/content/docs/search-config.md @@ -58,3 +58,33 @@ Defaults to "/". If hosting a site on a subpath, `baseUrl` can be provided, and ``` Overrides the bundle directory. In most cases this should be automatically detected by the import URL. Set this if search isn't working and you are seeing a console warning that this path could not be detected. + +### Language + +```json +{ + "language": "pt-br" +} +``` + +Load a specific language index. Only applies to indexes being merged with [multisite search](/docs/multisite). + +### Index weight + +```json +{ + "indexWeight": 2 +} +``` + +Multiplies the scores of all results from this index by the given factor. Only applicable when using [multisite search](/docs/multisite). + +### Index weight + +```json +{ + "indexWeight": 2 +} +``` + +Multiplies the scores of all results from this index by the given factor. Only applicable when using [multisite search](/docs/multisite). diff --git a/pagefind/features/multisite/multisite_filters.feature b/pagefind/features/multisite/multisite_filters.feature index dc18d26a..06cd6d59 100644 --- a/pagefind/features/multisite/multisite_filters.feature +++ b/pagefind/features/multisite/multisite_filters.feature @@ -74,12 +74,12 @@ Feature: Multisite Filters async function() { let pagefind = await import("/website_a/_pagefind/pagefind.js"); await pagefind.options({ - indexFilter: { + mergeFilter: { site: "A" } }); await pagefind.mergeIndex("/website_b/_pagefind/", { - indexFilter: { + mergeFilter: { site: ["B", "C"] } }); diff --git a/pagefind/src/output/stubs/search.js b/pagefind/src/output/stubs/search.js index 1f4754d5..c1f60aad 100644 --- a/pagefind/src/output/stubs/search.js +++ b/pagefind/src/output/stubs/search.js @@ -27,7 +27,7 @@ class PagefindInstance { } this.indexWeight = opts.indexWeight ?? 1; - this.indexFilter = opts.indexFilter ?? {}; + this.mergeFilter = opts.mergeFilter ?? {}; this.loaded_chunks = {}; this.loaded_filters = {}; @@ -53,9 +53,9 @@ class PagefindInstance { } async options(options) { - const opts = ["basePath", "baseUrl", "indexWeight", "indexFilter"]; + const opts = ["basePath", "baseUrl", "indexWeight", "mergeFilter"]; for (const [k, v] of Object.entries(options)) { - if (k === "indexFilter") { + if (k === "mergeFilter") { let filters = this.stringifyFilters(v); let ptr = await this.getPtr(); this.raw_ptr = this.backend.add_synthetic_filter(ptr, filters);