facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
54.43k stars 8.16k forks source link

Algolia plugin SearchPage does not respect configuration #3805

Open slorber opened 3 years ago

slorber commented 3 years ago

🐛 Bug Report

Use some algolia config like:

    algolia: {
      apiKey: '47ecd3b21be71c5822571b9f59e52544',
      indexName: 'docusaurus-2',
      contextualSearch: true,
      searchParameters: {facetFilters: ['bad:filter']},
    },

Due to the presence of bad:filter, it should actually never find any result.

But the current search page does not respect the plugin configuration options.

We should rather make the search page results consistent with the navbar search input / modal results, and use the plugin options.

Edit: if contextual search is not enable, we should not append any facet filter to the query by default, to prevent issues such as https://github.com/facebook/docusaurus/issues/4644

ayshiff commented 3 years ago

@slorber Can I work on this ?

slorber commented 3 years ago

yes @ayshiff thanks, but let's first see how complex it might be

Note, some users want to use both contextual search + additional facetFilters at the same time (https://github.com/facebook/docusaurus/pull/3804)

@shipow @francoischalifour the Algolia API we use for that search page looks different than the one we use for the Navbar input/dropdown (DocSearch), wonder if you know how we could make this more consistent, and also use docsearch apis on the search page instead of algoliasearch/lite and algoliasearch-helpers?

It looks to me that the algolia site config we have is DocSearch props, but for the search page, we would have to convert searchParameters.facetFilters = ["customTag:value"] to disjunctiveFacets: ['customTag'] and algoliaHelper.addDisjunctiveFacetRefinement("customTag:value"), and it may not be very convenient to write this conversion logic. Wonder if we could use the same DocSearch props against both the dropdown, and an imperative search api.

Files:

TomPeirs commented 3 years ago

Note, some users want to use both contextual search + additional facetFilters at the same time (#3804)

Exactly, we are one of those users.

Still relevant in Alpha.75 -> https://docs.boc-group.com/adonis/en/ When I search for "API" the modal search box returns proper results. But the SearchPage does not respect our facetfilter.

sparanoid commented 3 years ago

My site is a single language project in Chinese. With contextualSearch set to false I still have the similar issue that language option is always passed to facetFilters in SearchPage which causes it does not return any result.

slorber commented 3 years ago

The Search Page does not respect contextualSearch: false either and always use facet filters for querying.

But it should still work, unless your Algolia index config is not up-to-date or it didn't crawl your site yet with the algolia plugin enabled. If your site is correctly configured (which I can't verify without seeing the conf and live URL), filtering on language should work.

sparanoid commented 3 years ago

@slorber Thanks for explaining. I'm using docusaurus-2.json and self-hosted scraper with Docker. You can see the live demo here: https://openbayes-docs.pages.dev/docs

slorber commented 3 years ago

The algolia theme is well installed on your site, and it has correct metadatas:

<meta data-react-helmet="true" name="docsearch:docusaurus_tag" content="docs-default-current"

The config looks fine, but you probably have to set your own site's start URL so that it crawls your site instead of the Docusaurus site.

  "index_name": "docusaurus-2",
  "start_urls": [
    "https://docusaurus.io/"
  ],
  "sitemap_urls": [
    "https://docusaurus.io/sitemap.xml"
  ],

However, I'm surprised it does not work only in the search page.

Also, if the modal does not work for contextualSearch: true, that is likely to hide some potential problem and the fields we query on are not indexed correctly.

@shortcuts any idea what could be going on? I'm not very familiar with the self-hosted scraper

sparanoid commented 3 years ago

I re-scrap our site with the start_urls matched to our master branch deployment (I just updated the URL in previous comment) and now everthing seems working.

An unrelated issue I found is when typing something in the input it loses focus eveytime. But this is not reproducible on https://docusaurus.io/search

slorber commented 3 years ago

Great that the recrawl fixed it. The other issue you mention is already fixed on master and will be in beta.4 (https://github.com/facebook/docusaurus/issues/5100) but you can use canary if you want: https://docusaurus.io/community/canary

peirstom commented 2 years ago

Hi, any update on this ticket?

jsphstls commented 11 months ago

This continues to affect Docusaurus instances by creating an unexpected difference in behavior between the search bar and the search page. The solution was already discussed. What does this issue need to move forward?

imroc commented 9 months ago

Still not fixed after 3 years?

deepaksood619 commented 4 months ago

Still not fixed

antoinetissier commented 3 months ago

Hello, this is an issue in our project as well: we have custom facet filters that are required for the search to work properly, but they are not included in the query sent by the search page, so it consistently yields no results.

This looks especially bad when the user ends up on the search page as a result of clicking the "See all x results" link from the bottom of the search results dropdown.

Is there any chance that this issue is fixed in the near feature ? In the meantime, are there workarounds ? In particular I was thinking of maybe swizzling the SearchPage component, but it sounds a bit hacky and so feedback is welcome before getting into it.

Thanks a lot !

slorber commented 3 months ago

This issue is unfortunately not a top priority for me right now. If someone from the community wants to work on it I'd be happy to review their PR but I can't work on it myself in the near future.