docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Algolia plugin SearchPage does not respect configuration

Open slorber opened this issue 5 years ago • 15 comments

🐛 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

slorber avatar Nov 23 '20 18:11 slorber

@slorber Can I work on this ?

ayshiff avatar Nov 25 '20 09:11 ayshiff

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:

  • https://github.com/facebook/docusaurus/blob/master/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.js
  • https://github.com/facebook/docusaurus/blob/master/packages/docusaurus-theme-search-algolia/src/theme/SearchPage/index.js

slorber avatar Nov 25 '20 12:11 slorber

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.

TomPeirs avatar Jun 22 '21 15:06 TomPeirs

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.

sparanoid avatar Jul 01 '21 11:07 sparanoid

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.

slorber avatar Jul 01 '21 13:07 slorber

@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

sparanoid avatar Jul 02 '21 02:07 sparanoid

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

slorber avatar Jul 02 '21 08:07 slorber

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

sparanoid avatar Jul 02 '21 09:07 sparanoid

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

slorber avatar Jul 05 '21 10:07 slorber

Hi, any update on this ticket?

peirstom avatar Jul 07 '22 15:07 peirstom

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?

jsphstls avatar Aug 11 '23 18:08 jsphstls

Still not fixed after 3 years?

imroc avatar Oct 14 '23 08:10 imroc

Still not fixed

deepaksood619 avatar Mar 13 '24 19:03 deepaksood619

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 !

antoinetissier avatar Apr 03 '24 17:04 antoinetissier

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.

slorber avatar Apr 04 '24 09:04 slorber