Introduction
Have you ever noticed how search engines like Google suggest text as you type? That’s autocomplete in action—a feature that helps users find what they’re looking for faster by delivering suggestions in real-time.
In this article, we’ll show you how we implemented autocomplete in our GitHub Issue Search demo using Manticore Search. Whether you’re building a similar feature or just curious about the process, this guide will walk you through the basics.
What You’ll Need
- Manticore Search (development preview release or newer. Check the changelog to see if it has been already officially released.
- The Manticore Search PHP client
- Basic knowledge of PHP
Basic Implementation
While autocomplete functionality requires client-side JavaScript for the user interface (which we won’t cover here), implementing the backend component is straightforward. Simply create an endpoint that communicates with Manticore Search using the official PHP SDK to retrieve and return suggestions.
$client = new Client();
$result = $client->autocomplete([
'body' => [
'table' => 'your_table',
'query' => 'user_input',
],
]);
That’s it! This endpoint receives user input, queries Manticore Search, and returns suggestions. Pair it with JavaScript on the frontend to display results in real-time, and you’ve got yourself a smooth autocomplete experience.
See it in action here.
Advanced Features
While autocomplete functionality works well out of the box, you can enhance it with features like fuzzy matching and keyboard layout support. Here’s how to implement these features using Manticore Search’s PHP client.
Adding Fuzzy Matching
Users make typos — it happens. With fuzzy matching, you can return relevant suggestions even when queries aren’t perfectly typed. Here’s how to enable it:
$result = $client->autocomplete([
'body' => [
'table' => 'your_table',
'query' => 'user_input',
'options' => [
'fuzziness' => 1
],
],
]);
Multi-language Support with Keyboard Layouts
If your application serves users in different languages, keyboard layout support can make a big difference. Here’s an example of adding support for US English, Ukrainian and Russian layouts:
$result = $client->autocomplete([
'body' => [
'table' => 'your_table',
'query' => 'user_input',
'options' => [
'fuzziness' => 1,
'layouts' => ['us', 'ru', 'ua']
],
],
]);
This ensures users get accurate suggestions no matter what keyboard layout they’re using.
How We Did It: GitHub Issue Search Demo
In our Github Issue Search Demo, we enable search functionality across both issues and comments. We’ve implemented a single endpoint that queries Manticore Search twice and merges the results into a unified response. For implementation details, check out the source code.
The frontend implementation uses vanilla JavaScript with debounced event listeners for efficient query handling. View the complete implementation here.
Conclusion
Implementing autocomplete with Manticore Search’s PHP client is both straightforward and flexible. The combination of fuzzy matching and keyboard layout support makes it particularly effective for real-world applications.
For a practical example, explore our GitHub Issue Search Demo, where we’ve implemented these features in a production environment.