# Manticore Search PHPStorm support

Guide on configuring PHPStorm to work with Manticore Search. It covers the fundamental steps, from initializing Manticore Search using Docker to executing various SQL commands.

Manticore offers limited support for PHPStorm. In this article, I will outline the fundamental steps for configuring the IDE to work with Manticore. I am using IDE version 2023.2.4; support may not be available in earlier or later versions.

## Initialization

1. Launch Manticore Search. For example, let's use Docker:
```bash
docker run -p 9306:9306 --name manticore --rm -d manticoresearch/manticore:dev-6.2.13-cbf9350
```
2. Now we need to configure the data source. For this, we will use the MySQL driver that supports Manticore Search. Open the plugin `Database -> New -> Data Source -> MySQL` and complete the `Port` and `Authentication` fields as shown below:
![Fill data source](./manticoresearch-phpstorm-support/fill-data-source.png)
3. Click on the `Test Connection` button to ensure the source is configured correctly.
![Check Connection](./manticoresearch-phpstorm-support/check-connection.png)
4. After saving the configuration, the database tab will display the interface for working with Manticore Search.
![Database after source configuration](./manticoresearch-phpstorm-support/database-after-source-configuration.png)

## Using Manticore Search in PHPStorm

### Create tables

For creating tables, it's preferable to use the console `Ctrl+Shift+F10`

```mysql
create table products(title text, price float) morphology='stem_en';
```

In case you decide to use the UI, remove the `Manticore.products` database from the table creation command, leaving only `products`.

### INSERT

To insert data into Manticore via PHPStorm, you can use the console and the UI:

#### Console
```mysql
insert into products(title, price) values ('Crossbody Bag with Tassel', 19.85), ('microfiber sheet set', 19.99), ('Pet Hair Remover Glove', 7.99);

# 3 rows affected in 18 ms
```

#### UI
Set the `id` value to `0` instead of the default `null` if you want the id to be auto-generated.
![Insert via ui](./manticoresearch-phpstorm-support/insert-via-ui.png)

Upon opening the table, you can see the data that was just added.
![Inserted data example.png](./manticoresearch-phpstorm-support/inserted-data.png)

### SELECT
It's better to use the console for SELECTs since the `MATCH()` SQL statement has a different format in MySQL, and the UI considers it erroneous.
```mysql
select * from products where match('pet')
```
![Select with match operator](./manticoresearch-phpstorm-support/select-match.png)

### UPDATE
Updates should only be performed in the console.
```mysql
update products set price=18.5 where id = 8217058505249521668;

# 1 row affected in 12 ms
```

### DELETE
Deletions can only be done through the console.
```mysql
delete from products where id = 8217058505249521668;

# 1 row affected in 12 ms
```

### PQ

Percolate queries support is also implemented only at the console level.

1. Create pq table
```mysql
CREATE TABLE pq_table(title text, color string) type='pq';
```

2. Populate with data
```mysql
INSERT INTO pq_table(query) values('@title bag');
INSERT INTO pq_table(query,filters) values('@title shoes', 'color=\'red\'');
INSERT INTO pq_table(query,filters) values('@title shoes', 'color in (\'blue\', \'green\')');
select * from pq_table;
```
![PQ select](./manticoresearch-phpstorm-support/pq-select.png)

3. Run `CALL PQ` command
```
CALL PQ('pq_table', 'What a nice bag', 0 as docs_json);
```
![Call PQ](./manticoresearch-phpstorm-support/call-pq.png)

## Conclusion

In conclusion, integrating Manticore Search with PHPStorm, particularly the 2023.2.4 version, is a straightforward yet nuanced process. It is important to remember that Manticore Search, while accessible through MySQL IDEs like PHPStorm, is not MySQL itself. This distinction brings certain limitations in how the IDE interacts with Manticore Search.
