-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Docusaurus sends incorrect Algolia DocSearch request under /search #5084
Comments
I've parsed the params above for easier comparison. Here's the bad request: {
"requests": [
{
"indexName": "memfault",
"params": {
"hitsPerPage": "15",
"advancedSyntax": "true",
"query": "nrf",
"page": "0",
"facets": "[\"language\",\"docusaurus_tag\"]",
"tagFilters": "",
"facetFilters": "[[\"language:en\"],[\"docusaurus_tag:default\",\"docusaurus_tag:docs-default-current\"]]"
}
},
{
"indexName": "memfault",
"params": {
"hitsPerPage": "1",
"advancedSyntax": "true",
"query": "nrf",
"page": "0",
"attributesToRetrieve": "[]",
"attributesToHighlight": "[]",
"attributesToSnippet": "[]",
"tagFilters": "",
"analytics": "false",
"clickAnalytics": "false",
"facets": "language",
"facetFilters": "[[\"docusaurus_tag:default\",\"docusaurus_tag:docs-default-current\"]]"
}
},
{
"indexName": "memfault",
"params": {
"hitsPerPage": "1",
"advancedSyntax": "true",
"query": "nrf",
"page": "0",
"attributesToRetrieve": "[]",
"attributesToHighlight": "[]",
"attributesToSnippet": "[]",
"tagFilters": "",
"analytics": "false",
"clickAnalytics": "false",
"facets": "docusaurus_tag",
"facetFilters": "[[\"language:en\"]]"
}
}
]
} And here's the correct request: {
"requests": [
{
"indexName": "memfault",
"query": "nrf",
"params": {
"hitsPerPage": "20",
"highlightPreTag": "<mark>",
"highlightPostTag": "</mark>",
"attributesToRetrieve": "[\"hierarchy.lvl0\",\"hierarchy.lvl1\",\"hierarchy.lvl2\",\"hierarchy.lvl3\",\"hierarchy.lvl4\",\"hierarchy.lvl5\",\"hierarchy.lvl6\",\"content\",\"type\",\"url\"]",
"attributesToSnippet": "[\"hierarchy.lvl1:10\",\"hierarchy.lvl2:10\",\"hierarchy.lvl3:10\",\"hierarchy.lvl4:10\",\"hierarchy.lvl5:10\",\"hierarchy.lvl6:10\",\"content:10\"]",
"snippetEllipsisText": "…",
"facetFilters": "[]"
}
}
]
} |
I've managed to confirm that changing |
FYI the search page is a bit out-of-date and using an older/different API from Algolia. What I see:
This is a bit confusing but you have to deploy first a site with the algolia theme somewhere, get your index populated correctly, to only then be able to query it appropriately. You can either run the Algolia crawler locally, or wait 24h after the prod deployment (or ask DocSearch team for a crawl), or use a staging deployment as start_url temporarily. If you deploy this to production, it should start working within 24h A good way to see if your index contains the correct metadata is to use |
I see! I suppose I could think up a documentation patch for Docusaurus where I try to clarify this? I think it's easy for future developers to fall into the same trap. Developers may not feel confident enough to deploy the service to production if it's not working fully. Thanks a lot for your clarification. |
Yes, it's not the first time this comes up. Actually we decouple Docusaurus from Algolia, and the search tags we put by default in pages are generic and overrideable by any search plugin (ie you can build one for Elastic if you want). // Note: we don't couple this to Algolia/DocSearch on purpose
// We may want to support other search engine plugins too
// Search plugins should swizzle/override this comp to add their behavior
export default function SearchMetadatas({
locale,
version,
tag,
}: Props): JSX.Element {
return (
<Head>
{locale && <meta name="docusaurus_locale" content={locale} />}
{version && <meta name="docusaurus_version" content={version} />}
{tag && <meta name="docusaurus_tag" content={tag} />}
</Head>
);
} // Override default/agnostic SearchMetas to use Algolia-specific metadatas
export default function AlgoliaSearchMetadatas({locale, version, tag}) {
const language = locale;
return (
<Head>
{language && <meta name="docsearch:language" content={language} />}
{version && <meta name="docsearch:version" content={version} />}
{tag && <meta name="docsearch:docusaurus_tag" content={tag} />}
</Head>
);
} In theory, it is a good idea but in practice most of our users use DocSearch. Previously we added the DocSearch metadatas even when the plugin is not used, and we didn't have this problem. I'm thinking of re-biasing Docusaurus toward DocSearch usage, this looks more pragmatic |
Closing because we already re-biased search metadata to Algolia by default (more convenient, less confusing for users), and we have an issue to track the differences between search page + search modal (#3805) |
🐛 Bug Report
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
Docusaurus' Algolia DocSearch integration, added following Docusaurus docs, results in a problem where searches using the widget return correct results. However, searching under
website.com/search
always produces zero hits. The bug becomes more apparent when searching through the widget: a link "See all 43 results" appears, but when clicking it, the resulting/search?q=query
page displays "No results were found".Have you read the Contributing Guidelines on issues?
Yes
Steps to reproduce
/search
.Expected behavior
The search behaves the same, or similarly to the results in the search widget.
Actual behavior
See the bug description.
Your environment
2.0.0-beta.2
Reproducible demo
https://codesandbox.io/s/hardcore-lehmann-pwvxd?file=/docusaurus.config.js
nrf
Additional context
I've diffed the requests from the widget and the requests from
/search
. Apparently, only the parameters are different:...where
request-correct.json
contains the params of the request that produced the expected results, andrequest-bad.json
the params of the request that produced no results.The text was updated successfully, but these errors were encountered: