-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Algolia includes result from different locales but redirecting shows 404 #5880
Comments
Can't reproduce. Can you try reproducing this on the Docusaurus site? https://docusaurus.io/ I tried with https://docusaurus.io/zh-CN/ and Algolia worked correctly. It could be a problem with the page itself instead of Algolia—is it a doc page, or a custom page? |
|
I want to search based on language selected like in https://docusaurus.io/ |
@code-masala That query payload is far from enough for me to figure out what's wrong. Do you have a reproducible demo? A published site? |
@Josh-Cena |
@Josh-Cena can you help me to figure out that what change I have to do in config.json |
As I said, I can't help you much without having a site to look at. I've never observed the behavior you described. |
It's not clear what you mean here, please show at least a screenshot @code-masala we can't really help on this without inspecting your real live site URL and your algolia index config. We'll re-open once it's provided. |
I also have the same problem . |
@casionone Weirdly, I can't reproduce it at all... |
760d14dc-4a40-4e23-8698-931579541342.mp4 |
Thanks. This is because Algolia uses an SPA redirect but the en locale and zh-Hans locale are two different SPAs. |
@casionone the issue is that your English site is presenting Chinese search results. This also seems to be the original problem:
We can see in the network tab that your site is not sending any facetFilter: You should enable https://docusaurus.io/docs/search#contextual-search It's a good time to enable this feature by default, will do that in #6407 |
However, we still need to fix some i18n edge cases, because the "Recent" search results are shared across languages, and we can still get a 404 in some situations (like clicking on a recent Chinese search result while on the English site). I can reproduce this on the Docusaurus prod site, and contextualSearch won't fix it. |
Re-opening because there are still edge cases to fix, see my comment above |
Hi @slorber, @Josh-Cena, I've have the same problem as @casionone. We have intentionally disabled contextualSearch to be able to search in different languages, and now are receiving "Page not found" when selecting a search result with different locale. It is possible to try it here: https://orange-field-06c9e2f03.azurestaticapps.net/ Is there any quick workaround possible? Maybe inject something like "pathname://" to search results? When doing the search from an already localized page, it is even worse, as it appends a second locale to the URL: https://orange-field-06c9e2f03.azurestaticapps.net/en-US/uk-UA/docs/hrp/doc-approval-workflow I found an issue #4723 and PR #6731 regarding this, but it is unfinished for a long time. |
@sergeyol by default we assume search results are part of the current single-page application, and are navigated using When using i18n, each locale is a different SPA site and we should use We have an externalUrlRegexp that maybe could be a solution? The upcoming version 2.3 should also allow you to wrap the SearchBar and provide a custom |
Thank you @slorber, indeed, I was not aware of that parameter, and it does the job for me. I've added our whole domain for now. Will also wait for 2.3 version, sounds promising. |
Regarding the edge case for contextualSearch mentioned above, I'm still able to reproduce it in version 2.4. However, the docusaurus prod website doesn't seem to have this problem. Is there a PR for this fix that's not released? |
@tri-chu this issue is quite old and contextualSearch not new. I don't think we fixed anything related to that recently. If you have issues it's very difficult for me to help if you don't share your crawler config and your live production URL to see the problem myself. |
Going to close this because contextualSearch is now enabled by default. The only remaining edge case ("recent search hit in Chinese while you are on the English site", see #5880 (comment)) is now very unlikely to happen unless the user decide for some reason to disable contextual search, which I wouldn't particularly recommend. |
Hi @slorber we're still hitting that problem pretty consistently on docusaurus 2.4 with contextual search turned on on our website here https://www.8thwall.com/docs/ We don't use the new Algolia Crawler but the legacy crawler with this config instead {
"index_name": "8thwall-docs-prod",
"start_urls": [
"https://www.8thwall.com/docs/"
],
"sitemap_urls": [
"https://www.8thwall.com/docs/sitemap.xml"
],
"selectors": {
"lvl0": {
"selector": "(//ul[contains(@class,'menu__list')]//a[contains(@class, 'menu__link menu__link--sublist menu__link--active')]/text() | //nav[contains(@class, 'navbar')]//a[contains(@class, 'navbar__link--active')]/text())[last()]",
"type": "xpath",
"global": true,
"default_value": "Documentation"
},
"lvl1": "header h1",
"lvl2": "article h2",
"lvl3": "article h3",
"lvl4": "article h4",
"lvl5": "article h5, article td:first-child",
"text": "article p, article li, article td:last-child"
},
"strip_chars": " .,;:#",
"custom_settings": {
"separatorsToIndex": "_",
"attributesForFaceting": [
"language",
"version",
"type",
"docusaurus_tag"
],
"attributesToRetrieve": [
"hierarchy",
"content",
"anchor",
"url",
"url_without_anchor",
"type"
]
}
} |
Here is a screen recording of our issue: Screen.Recording.2023-04-27.at.2.24.58.PM.mov |
Thanks @tri-chu , you are right this edge case of "recent searches" is still common when user switch language. @shortcuts is there a way to sandbox each language regarding recent searches? This looks stored in localStorage under I saw this in the DocSearch docs but nothing to customize the localStorage key https://docsearch.algolia.com/docs/api/#disableuserpersonalization Also curious: what are favorites? is there a way to add a page as favorite now? 🤔 |
Actually it's already stored with the correct key, we use the
Yes, a user can add recent searches to favorite, it's also a local storage thing |
Oh, forgot about this favorite feature :D @shortcuts I'm not sure to understand what you mean here What I see in practice is that a single local storage key is used for all the Docusaurus localized sites: I don't really understand what the What I'd like is the ability to provide my own storage key, so that we have more than 1 storage value:
Does it make sense? That also looks simpler easier to reason about and more performant because you are working with smaller recent search storage objects. The alternative for Docusaurus could be to not sandbox locales, but make it possible for Docusaurus to know if a search it is from another localized site, so that we can decide if we should navigate SPA ( Technically we could probably do that already, but it's more complicated, and there are possible fancy edge cases if we build this by inspecting the search hit URL language prefix (convoluted: To the the ability to pass custom storage keys is simpler and probably good enough |
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
https://domain.com/ur/hello
if this route is given by algolia search When i redirect then it will 404.When I refresh the page with same route It works
Steps to reproduce
Step1-Open algolia search bar
Step2-Write something for search
Step3-click
Expected behavior
When I click on search data I have to redirect to the respective pages
Actual behavior
Give 404 first . If I manually refresh then It works fine
Your environment
Reproducible demo
No response
Self-service
The text was updated successfully, but these errors were encountered: