Manticore Search is an open-source full-text search engine that supports fast querying and real-time indexing. It is commonly used in website search, content management systems, and e-commerce platforms. This article demonstrates how to integrate Manticore Search with PHP to implement a practical full-text search feature.
To use Manticore Search, the first step is to download and install it, followed by basic configuration.
Visit the Manticore Search official website and download the version suitable for your operating system. On Debian-based systems (like Ubuntu), you can install it using the following commands:
sudo apt-get update
sudo apt-get install manticore
After installation, modify the configuration file to enable service and logging. Here’s an example configuration:
indexer {
mem_limit = 128M
}
searchd {
listen = 9306:mysql41
log = /var/log/manticore/searchd.log
query_log = /var/log/manticore/query.log
read_timeout = 5
}
Once configured, build the index using the following command:
sudo indexer --all --rotate
Now let’s implement the search functionality in PHP.
Use Composer to install the official PHP client:
composer require manticoresoftware/manticoresearch-php
Below is an example of connecting to Manticore Search and performing a keyword query in PHP:
<?php
use Manticoresearch\Query\BoolQuery;
use Manticoresearch\Query\Match;
use Manticoresearch\Query\QueryString;
use Manticoresearch\Search;
// Create search query
$search = new Search();
$query = new BoolQuery();
$query->addMust(new Match('content', 'keyword'));
$search->setQuery($query);
// Execute search
$results = $search->search();
// Output results
foreach ($results['hits']['hits'] as $hit) {
echo $hit['_id'] . ': ' . $hit['_source']['content'] . '<br>';
}
?>
In this example, we use BoolQuery with a Match clause to define the keyword search, then execute the search and display the results.
This article explained how to implement a full-text search feature using PHP and Manticore Search. From installing and configuring the search engine to writing PHP code to execute queries, it provides a clear development path.
With this approach, developers can easily implement customizable, high-performance search functionality to enhance content discovery for users.