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

Set queryType: 'prefixAll' #107

Open
paolochang opened this issue Jun 19, 2023 · 0 comments
Open

Set queryType: 'prefixAll' #107

paolochang opened this issue Jun 19, 2023 · 0 comments

Comments

@paolochang
Copy link

I found the query use the last prefix when it has more than a word. So I did some research and found that algolia support queryType to set the prefix of the query. I tried set the queryType to prefixAll but it seems not working. Does docusaurus-lunr-search support to set the query type?

See this document: algolia API Reference / API Parameters / Query Type

/**
   * Returns the `source` method to be passed to autocomplete.js. It will query
   * the Algolia index and call the callbacks with the formatted hits.
   * @function getAutocompleteSource
   * @param  {function} transformData An optional function to transform the hits
   * @param {function} queryHook An optional function to transform the query
   * @returns {function} Method to be passed as the `source` option of
   * autocomplete
   */
getAutocompleteSource(transformData, queryHook) {
  return (query, callback) => {
    if (queryHook) {
      // eslint-disable-next-line no-param-reassign
      query = queryHook(query) || query;
    }
    this.client
      .search(query, {
        queryType: 'prefixAll',
      })
      .then((hits) => {
        if (
          this.queryDataCallback
                    && typeof this.queryDataCallback === 'function'
        ) {
          this.queryDataCallback(hits);
        }
        if (transformData) {
          hits = transformData(hits) || hits;
        }
        callback(DocSearch.formatHits(hits));
      });
  };
}
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

1 participant