Add configurable minimum characters setting for autocomplete #508
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a configurable minimum characters setting for autocomplete search to reduce API calls to Algolia.
Problem
Currently, autocomplete triggers on every keystroke starting from the first character, which can generate excessive API calls to Algolia, especially for sites with high search traffic.
Solution
This PR adds a configurable "Minimum Characters" setting that allows administrators to specify how many characters users must type before autocomplete search begins.
Changes
algolia_autocomplete_min_charssetting (default: 3 characters)minLengthparameterBenefits
Files Modified
includes/class-algolia-settings.php- Added setting and getter methodincludes/indices/class-algolia-index.php- Added to default configincludes/admin/class-algolia-admin-page-autocomplete.php- Added admin interfaceincludes/class-algolia-template-loader.php- Pass setting to frontendtemplates/autocomplete.php- Apply minLength to autocomplete.jsTesting
Usage
Navigate to WordPress Admin > Algolia Search > Autocomplete and configure the "Minimum Characters" field (default: 3).
This addresses the need to reduce API calls while maintaining good user experience.