-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
DanRoscigno
wants to merge
5
commits into
facebook:main
Choose a base branch
from
DanRoscigno:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+123
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
 | ||
|
||
## 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) | ||
|
||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.