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

Is there a way to alter algolia autocomplete config to use debounce feature #398

Open
acividini92 opened this issue Feb 13, 2024 · 1 comment

Comments

@acividini92
Copy link

Is your feature request related to a problem? Please describe.
We're trying to reduce the amount of calls done to Algolia, as we're charged per request, and I'm reading that autocomplete.js has a debounce option but I can't find a filter to apply that configuration. We're attaching the autocomplete function to the default WP search field by not altering the default selector.

Describe the solution you'd like
Something like a filter for altering these options as I'm trying to do here, maybe it's there but I can't find the proper approach

add_filter('algolia_autocomplete_config', 'algolia_autocomplete_config_custom');
function algolia_autocomplete_config_custom($config) {
  foreach ($config as &$item) {
    $item['debounce'] = 2500;
  }
  return $config;
}

add_filter('algolia_config', 'algolia_config_custom');
function algolia_config_custom($config) {
  $config['debounce'] = 2500;
  foreach ($config['indices'] as &$index) {
    $index['debounce'] = 2500;
  }
  return $config;
}

Describe alternatives you've considered
I tried patching my local version of this project but I can't seem to find the place where the autocomplete is initialized.

Additional context
No additional context, just seeking for help as it sounds unrealistic that nobody had endpoint hitting rate issue before.

Thanks everyone

@tw2113
Copy link
Member

tw2113 commented Feb 13, 2024

I know I have my replies over at #380 about the exact same topic.

Your use of the filters would definitely be one way to get something into the configuration variable, but it'd still need to be passed in as part of the code used in autocomplete.php file.

As per the documentation info at https://github.com/algolia/autocomplete/tree/v0.38.0#datasets, you'd want to set the configured time in milliseconds alongside this code: https://github.com/WebDevStudios/wp-search-with-algolia/blob/main/templates/autocomplete.php#L108-L151

Perhaps right before the templates property around line 117. Based on your code examples above:

debounce: config['debounce'],

Let us know if you need some guidance/pointers on how to best customize the template files safely, we definitely have documentation on that topic as well.

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