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

Load search index, when component is shown. #37

Closed
chrispreisler opened this issue Apr 30, 2020 · 2 comments
Closed

Load search index, when component is shown. #37

chrispreisler opened this issue Apr 30, 2020 · 2 comments

Comments

@chrispreisler
Copy link

Hey,

I would like to load the search index, when the user opens a search overlay on a page. The overlay can be opened from different routes, so I can't use the autoFetch with defining pathes. As I understand your text right I can set the autoFetch to false and then load the search index in someway. Do you have an example for that or can point me in the right direction?

Thank you very much for your help in advance.

Best regards
Chris

@travis-r6s
Copy link
Owner

That's correct - if you look at this line here: https://github.com/thetre97/gridsome-plugin-flexsearch/blob/2d166f5e7fce275ba7b2f8597b0a3ed416578c1b/gridsome.client.js#L10 that shows an example of how to fetch the json.

You could do something like:

import FlexSearch from 'flexsearch'
import cjson from 'compressed-json'

export default {
  async mounted () {
    const searchIndex = await fetch(`/flexsearch.json`).then(r => r.json()).then(j => cjson.decompress(j))
      this.$search.import(searchIndex, { serialize: false })
  }
}

@chrispreisler
Copy link
Author

Thank you so much. Included it right now and it works perfectly.

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