8000 Document a process for boosting pages in Algolia Docsearch by DanRoscigno · Pull Request #11111 · facebook/docusaurus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Document a process for boosting pages in Algolia Docsearch #11111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions website/docs/advanced/boosting.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
description: Guide readers to important docs with metadata.

---
# Algolia search boosting

Algolia DocSearch is a popular choice for Docusaurus sites. Algolia provides methods for boosting the ranking of pages in the search, and this guide covers a method using metadata added to pages and edits to the default Algolia crawler configuration.

## Steps

1. Configure Docusaurus to use Algolia DocSearch. To get started with DocSearch see [Search](../search.mdx).
2. Add metadata to pages that you would like to boost.
3. Configure your Algolia index to adjust page ranking based on the added metadata.
4. Configure the Algolia Crawler to use the added metadata.

## Add metadata

Here is an example of the desired metadata in a page to be boosted by 100 in the page ranking:

```html
<meta data-rh="true" name="pageBoost" content="100">
```

Adding metadata, other than `description` and `keywords`, is done by adding HTML within your Markdown/MDX files.

This is the edit to a Markdown/MDX file:

```md
---
title: Page name
---

<!-- highlight-start -->
<head>
<meta name="pageBoost" content="100"/>
</head>
<!-- highlight-end -->

## Overview
```

## Configure the Algolia index

Each Algolia index has several configuration options. The section to configure for page boosting is **Index** → **Configuration** → **Relevance Essentials** → **Ranking and Sorting** → **Custom Ranking**

If **`weight.pageRank`** is not in the list of custom ranking attributes, add it with **Add custom ranking attribute**.

## Configure the Algolia Crawler

The Algolia Crawler configuration is edited in your Algolia account. Access the crawler editor from the Algolia dashboard for your Algolia application at **Data sources** → **Crawler** by choosing the name of the crawler, and then **Editor**.

There are three edits to be made:

### Modify the `recordExtractor` function


:::tip
In the JavaScript snippets the `$` is the Cheerio instance, and allows you to manipulate the HTML Document Object Model (DOM). Links are in the **More information** section at the end of this doc.
:::

The `recordExtractor` needs access to the Cheerio instance to extract the metadata from the DOM.

Verify that the `recordExtractor` function includes the Cheerio instance as a parameter. Your record extractor function may have the `$`, if so you can skip this step. Your record extractor may also have other parameters listed, you should not remove parameters.

```js
recordExtractor: ({ $, helpers }) => {
```

### Extract the `pageBoost` metadata

Within the `recordExtractor` function, add the highlighted line to extract the `pageBoost` metadata into `const pageBoost`, with a default value of 0 if no metadata is present in the page.

```js
recordExtractor: ({ $, helpers }) => {
// highlight-start
// Extract metadata
const pageBoost = $("meta[name='pageBoost']").attr("content") || "0";
// highlight-end
```

### Assign the `pageRank`

The`pageRank` property is of type `string | number`, add the highlighted line to the `recordProps` code. In this example it is added after `content`.

```js
return helpers.docsearch({
recordProps: {

// your recordProps may populate lvl0 - lvl6 here

content: "article p, article li, article td:last-child",
// highlight-start
pageRank: Number(pageBoost),
// highlight-end
},
```

## Testing

1. To test the changes to the page metadata and the Algolia Crawler build and publish your Docusaurus site.
1. View the source of a modified page and check for the added `pageBoost` metadata. It should look like this (with the content you assigned) in the HTML:
```html
<meta data-rh="true" name="pageBoost" content="100">
```
1. Open the Crawler UI and test one of the pages you are boosting. Access the crawler editor from the Algolia dashboard for your Algolia application at **Data sources** → **Crawler** by choosing the name of the crawler, and then **Editor**. In the top navigation select **URL Tester** and test a boosted page, verify that `weight.pageRank` is set in the **Records** tab:
![Algolia test URL records](/img/boost/boost_algolia_test_url_records.png)

## Production

Run a production crawl after testing individual URLs and confirm the updated search results.

## More information

[Adding metadata](../guides/markdown-features/markdown-features-head-metadata.mdx)

Configuring [Search](../search.mdx)

Algolia Crawler [record extractor](https://docsearch.algolia.com/docs/record-extractor)




1 change: 1 addition & 0 deletions website/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const sidebars: SidebarsConfig = {
'advanced/routing',
'advanced/ssg',
'advanced/client',
'advanced/boosting',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very search/Algolia-specific, and doesn't really belong here.

At best, I'd prefer if we only add a little mention on this page: https://docusaurus.io/docs/search#using-algolia-docsearch

Preferably, it should be a very small section about Algolia boosting, linking to an external documentation written and kept up-to-date by the Algolia team itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will talk to the Algolia folks. thanks.

],
},
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
0