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

Ability to update options on the fly, or exposing an API to re-initialize docsearch #608

Closed
Justineo opened this issue Feb 15, 2019 · 4 comments

Comments

@Justineo
Copy link

Do you want to request a feature or report a bug?

Feature request. Following up #599 (comment).

My site uses a front-end router and I need docsearch to update options after user navigated to a new page from the front-end.

What is the current behavior?

The API only exposes an initialize function, lacking the ability to dispose or re-initialize from the front-end.

If the current behavior is a bug, please provide all the steps to reproduce and a minimal
JSFiddle example or a repository on GitHub that we can npm install
and npm start.

What is the expected behavior?

Docsearch can be re-initialized with different options, or setting new options on the fly.

@Justineo
Copy link
Author

After looking into the source code, I realized that it's already supported by modifying properties on the returned instance of the global docsearch API. I think it should be documented.

@s-pace
Copy link

s-pace commented Mar 12, 2019

Thanks for the update @Justineo

Would you mind providing more details regarding what you wanted to achieve? If you can share with us a code example, we would be happy to include it within your documentation.

@Justineo
Copy link
Author

@s-pace

I'm using a front-end router. After user navigates to a new URL that triggers locale change, I need to update the algoliaOptions of the docsearch instance.

Something like:

const instance = docsearch({ ... })

app.on('localechange', val => {
  instance.algoliaOptions.facetFilters = [`lang:${val}`]
})

@Justineo
Copy link
Author

Furthermore, I found the client.clearCache() method doesn't cover all cases. If we follow such steps:

  1. Search for 'a'
  2. Update algoliaOptions
  3. Run clearCache()
  4. Search for 'a' again

We'll still get the cached results. The data is cached inside the Dataset object deep inside. After some digging, I finally managed to find a way to correctly clear all cached result:

instance.autocomplete
  .eq(0).data('aaAutocomplete')
  .dropdown.datasets[0].clearCachedSuggestions()
instance.client.clearCache()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants