Skip to content
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

[v2] allow defining additional filters for algolia when using contextualSearch #3790

Closed
aeneasr opened this issue Nov 20, 2020 · 6 comments · Fixed by #3804
Closed

[v2] allow defining additional filters for algolia when using contextualSearch #3790

aeneasr opened this issue Nov 20, 2020 · 6 comments · Fixed by #3804
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@aeneasr
Copy link
Contributor

aeneasr commented Nov 20, 2020

🚀 Feature

#3550 introduces algolia.contextualSearch which is great as it simplifies indexing of versions and languages. However, it removes the ability to define other filters.

It would be great if we could allow both side-by-side and only throw warnings when language or version is overwritten.

Have you read the Contributing Guidelines on issues?

yes

Motivation

We have several projects that use the same algolia index/apiKey and want the search to return information relevant to the project being looked at, not every project.

@aeneasr aeneasr added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers labels Nov 20, 2020
@slorber
Copy link
Collaborator

slorber commented Nov 20, 2020

Hi,

We allow you to override Algolia searchParams.

image

Do you think we should somehow merge contextual search facetFilter with the one you provide in config?
Somehow, doing a deep merge instead of a shallow merge?

@aeneasr
Copy link
Contributor Author

aeneasr commented Nov 20, 2020

Yes, I meant the facetFilters. So the config would look something like this:

    algolia: {
      apiKey: '...',
      indexName: 'ory',
      contextualSearch: true,
      searchParameters: {
        facetFilters: [
           `tags:ory-hydra`,
        ]
      }
    },

This currently fails with:

Error: If you are using algolia.contextualSearch: true, you should not provide algolia.searchParameters.facetFilters, as it is computed for you dynamically

caused by this diff.

However, it would be nice to add additional filters to the default docusaurus filters - for example to browse specific projects or to just search in FAQ etc!

So I guess my reply to

Do you think we should somehow merge contextual search facetFilter with the one you provide in config?
Somehow, doing a deep merge instead of a shallow merge?

would be yes, exactly!

@slorber
Copy link
Collaborator

slorber commented Nov 20, 2020

I added this security because I didn't want users to forget to remove their facetFilter when enabling contextual search, otherwise it would likely mess-up with contextual search.

We'd rather think about a more explicit API to enrich the contextual filters with new ones, instead of removing this security.

@aeneasr
Copy link
Contributor Author

aeneasr commented Nov 20, 2020

Sure that works for me also! Could also be a function:

(facetFilters) => [...facetFilters, "foo:bar"]

@slorber
Copy link
Collaborator

slorber commented Nov 23, 2020

We can't allow such callback in node config because this callback has to be applied on client-side (after we compute appropriate contextual facet filters from current browser URL).

I couldn't find any good API for these additional filters, and I think it's safe to just remove the security: the user will notice if search doesn't return anything, and this is documented.

Fixed in #3804

@aeneasr
Copy link
Contributor Author

aeneasr commented Nov 23, 2020

Cool thanks!

@Josh-Cena Josh-Cena removed the status: needs triage This issue has not been triaged by maintainers label Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants