-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Send search request to Algolia with some delay #5174
Comments
The search modal is a react component provided by Algolia on which we don't have control, but we allow to customize it through props. It's unlikely Docusaurus will handle that throttle/deboucing logic. You'd rather ask the Algolia DocSearch team: if they implement this feature (maybe it already exists?), then Docusaurus will be able to use it by passing extra config options. ping @shortcuts |
Algolia has been already supported this feature. It's named |
Thanks @shortcuts Not sure how this works exactly but we already forward props to the React component exported as However this prop was already provided by @francoischalifour: const transformSearchClient = useCallback(
(searchClient) => {
searchClient.addAlgoliaAgent(
'docusaurus',
siteMetadata.docusaurusVersion,
);
return searchClient;
},
[siteMetadata.docusaurusVersion],
); And it's code that runs in the browser so it's not possible to pass a fn to the browser through Docusaurus config file. If this is the only exposed API, this means Docusaurus users will have to swizzle the component and override the existing transformSearchClient. It's not ideal but can be good enough, considering this usecase is not common. It would be simpler if the component accepted a serializable prop like |
@slorber The current docs suggest that all algolia options are supported by the docusaurus config: |
@xixixao it's not possible to provide any callback from Docusaurus config to the client-side JavaScript. If you want to allow passing If you want to make it easier (just wrapping instead of ejecting), I would be happy to accept a similar PR as this one: #8462 If there are props that are missing and we can add support, then I'm happy to do so => please submit a code PR. In case it's not possible to add support, happy to document so => please submit a doc PR. |
🚀 Feature
Now a new search request is sending to Aloglia on each query change. I want to reduce the number of requests to Aloglia. It would be nice if Docusarus will have some delay option n config. If the delay is set, the request will be sent if the user is not printing. Without delay in the config, the search behavior will be the same as now.
Have you read the Contributing Guidelines on issues?
Yes.
Motivation
This feature can reduce the number of requests to Algolia, and therefore reduce the costs of search.
API Design
Add new option to Algolia search plugin config. If the delay is set search query will be sent only after a user stops inputting the query. I assume that desired behavior can be easily achieved by React hooks. There is an example on StackOverflow: https://stackoverflow.com/questions/53071774/reactjs-delay-onchange-while-typing
Have you tried building it?
Unfortunately, I'm not a react developer, so I can't build it myself.
The text was updated successfully, but these errors were encountered: