Skip to content

Commit

Permalink
Document multisite filter merging
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Aug 23, 2022
1 parent b860f31 commit bd76c67
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
41 changes: 37 additions & 4 deletions docs/content/docs/multisite.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}
Expand All @@ -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 >}}
Expand Down
30 changes: 30 additions & 0 deletions docs/content/docs/search-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
4 changes: 2 additions & 2 deletions pagefind/features/multisite/multisite_filters.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
});
Expand Down
6 changes: 3 additions & 3 deletions pagefind/src/output/stubs/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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);
Expand Down

0 comments on commit bd76c67

Please sign in to comment.