You can install and start Manticore easily in Ubuntu, Centos, Debian, Windows and MacOS or use Manticore as a docker container.
- Ubuntu
- Debian
- Centos
- Windows
- MacOS
- Docker
wget https://repo.manticoresearch.com/manticore-repo.noarch.deb
sudo dpkg -i manticore-repo.noarch.deb
sudo apt update
sudo apt install manticore-bin
sudo systemctl start manticore
wget https://repo.manticoresearch.com/manticore-repo.noarch.deb
sudo dpkg -i manticore-repo.noarch.deb
sudo apt update
sudo apt install manticore-bin
sudo systemctl start manticore
sudo yum install https://repo.manticoresearch.com/manticore-repo.noarch.rpm
sudo yum install manticore
sudo systemctl start manticore
- Download Windows archive from https://manticoresearch.com/downloads/
- Extract all from the archive to C:\Manticore
-
C:\Manticore\bin\searchd --install --config C:\Manticore\sphinx.conf.in --servicename Manticore
- Start Manticore from the Services snap-in of the Microsoft Management Console
brew install manticoresearch
brew services start manticoresearch
docker pull manticoresearch/manticore
docker run --name manticore -p9306:9306 -p9308:9308 -p9312:9312 -d manticoresearch/manticore
For persisting your data directory read how to use Manticore docker in production
By default Manticore is waiting for your connections on:
- port 9306 for MySQL clients
- port 9308 for HTTP/HTTPS connections
- port 9312 for connections from other Manticore nodes and clients based on Manticore binary API
- SQL
- HTTP
- PHP
mysql -h0 -P9306
HTTP is a stateless protocol so it doesn't require any special connection phase:
curl -s "http://localhost:9308/search"
require_once __DIR__ . '/vendor/autoload.php';
$config = ['host'=>'127.0.0.1','port'=>9308];
$client = new \Manticoresearch\Client($config);
Let's now create an index called "products" with 2 fields:
- title - full-text field which will contain our product's title
- price - of type "float"
- SQL
- HTTP
- PHP
create table products(title text, price float) morphology='stem_en';
POST /sql -d "mode=raw&query=create table products(title text, price float) morphology='stem_en'"
$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float'],
]);
Query OK, 0 rows affected (0.02 sec)
{
"total":0,
"error":"",
"warning":""
}
- SQL
- HTTP
- PHP
insert into products(title,price) values ('Crossbody Bag with Tassel', 19.85), ('microfiber sheet set', 19.99), ('Pet Hair Remover Glove', 7.99);
"id":0
forces automatic ID generation.
POST /insert
{
"index":"products",
"id":0,
"doc":
{
"title" : "Crossbody Bag with Tassel",
"price" : 19.85
}
}
POST /insert
{
"index":"products",
"id":0,
"doc":
{
"title" : "microfiber sheet set",
"price" : 19.99
}
}
POST /insert
{
"index":"products",
"id":0,
"doc":
{
"title" : "Pet Hair Remover Glove",
"price" : 7.99
}
}
'id' => 0
forces automatic ID generation.
$index->addDocuments([
['id' => 0, 'title' => 'Crossbody Bag with Tassel', 'price' => 19.85],
['id' => 0, 'title' => 'microfiber sheet set', 'price' => 19.99],
['id' => 0, 'title' => 'Pet Hair Remover Glove', 'price' => 7.99]
]);
Query OK, 3 rows affected (0.01 sec)
{
"_index": "products",
"_id": 0,
"created": true,
"result": "created",
"status": 201
}
{
"_index": "products",
"_id": 0,
"created": true,
"result": "created",
"status": 201
}
{
"_index": "products",
"_id": 0,
"created": true,
"result": "created",
"status": 201
}
Let's find one of the documents. The query we will use is 'remove hair'. As you can see it finds document with title 'Pet Hair Remover Glove' and highlights 'Hair remover' in it even though the query has "remove", not "remover". This is because when we created the index we turned on using English stemming (morphology "stem_en"
).
- SQL
- HTTP
- PHP
select id, highlight(), price from products where match('remove hair');
POST /search
{
"index": "products",
"query": { "match": { "title": "remove hair" } },
"highlight":
{
"fields": ["title"]
}
}
$result = $index->search('@title remove hair')->highlight(['title'])->get();
foreach($result as $doc)
{
echo "Doc ID: ".$doc->getId()."\n";
echo "Doc Score: ".$doc->getScore()."\n";
echo "Document fields:\n";
print_r($doc->getData());
echo "Highlights: \n";
print_r($doc->getHighlight());
}
+---------------------+-------------------------------+----------+
| id | highlight() | price |
+---------------------+-------------------------------+----------+
| 1513686608316989452 | Pet <strong>Hair Remover</strong> Glove | 7.990000 |
+---------------------+-------------------------------+----------+
1 row in set (0.00 sec)
{
"took": 0,
"timed_out": false,
"hits": {
"total": 1,
"hits": [
{
"_id": "1513686608316989452",
"_score": 1680,
"_source": {
"price": 7.99,
"title": "Pet Hair Remover Glove"
},
"highlight": {
"title": [
"Pet <strong>Hair Remover</strong> Glove"
]
}
}
]
}
}
Doc ID: 1513686608316989452
Doc Score: 1680
Document fields:
Array
(
[price] => 7.99
[title] => Pet Hair Remover Glove
)
Highlights:
Array
(
[title] => Array
(
[0] => Pet <strong>Hair Remover</strong> Glove
)
)
Let's assume we now want to update the document - change the price to 18.5. This can be done by filtering by any field, but normally you know the document id and update something based on that.
- SQL
- HTTP
- PHP
update products set price=18.5 where id = 1513686608316989453;
POST /update
{
"index": "products",
"id": 1513686608316989453,
"doc":
{
"price": 18.5
}
}
$doc = [
'body' => [
'index' => 'products',
'id' => 2,
'doc' => [
'price' => 18.5
]
]
];
$response = $client->update($doc);
Query OK, 1 row affected (0.00 sec)
{
"_index": "products",
"_id": 1513686608316989400,
"result": "updated"
}
- SQL
- HTTP
- PHP
delete from products where price < 10;
POST /delete
{
"index": "products",
"query":
{
"range":
{
"price":
{
"lte": 10
}
}
}
}
$result = $index->deleteDocuments(new \Manticoresearch\Query\Range('price',['lte'=>10]));
Query OK, 1 row affected (0.00 sec)
{
"_index": "products",
"deleted": 1
}
Array
(
[_index] => products
[deleted] => 1
)