Mike: learning: First steps
Published: 2024-06-05 13:42:21

### About me


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azus44t0ajyeek82aode.jpg)
    Hello, I'm Mike.
    I recently started working at Manticore as a Developer Advocate. I am someone not completely distant from IT, but I'm catching up with modern technologies. In this blog, I'll share my experiences and what I learn about Manticore. I plan to document my journey in a diary format, explaining what Manticore is and how to use it. Let's discover how things work together, identify issues, and engage with developers in real time.
    This is my first blog post. If you are interested in learning about Manticore with me, I will keep you updated in:
    <ul>
      <li>
      <a href="https://twitter.com/manticoresearch">Twitter</a>
      </li>
      <li>
      Telegram: <a href="https://t.me/manticoresearch_en">EN</a> / <a href="https://t.me/manticore_chat">RU</a>
      </li>
      <li>
      <a href="https://slack.manticoresearch.com/">Slack</a>
      </li>
    </ul>
### A few words about Manticore

As I started learning about Manticore Search, I found out it's a powerful open-source database. It can do fast full-text searches using both SQL and JSON, and much more. It was created in 2017 and has been tested and improved a lot since then. Thanks to a strong community, many bugs have been fixed, and it works very well now.

Manticore is great for quickly finding words, phrases, and sentences, and it has many other advanced features. This makes it perfect for things like online stores and enterprise search systems. With lots of helpful features and support from the community and Manticore Software's team, it's easy to see why many people choose Manticore for their search needs.

In this article, I'll show you how to get started with Manticore

### Where to start
#### Minimal environment

* Internet
* Not too old OS (Mac, Win or Lin - it doesn’t matter)
* Docker or Docker Desktop.
* Relatively straight arms
* A strong desire to make the world better by creating high-quality, easy-to-use software with fast databases and search systems for full-text information.

#### Tools

* Console (or you can use Docker Desktop to connect to the container)
* File manager (optional, I like [Midnight Commander](https://midnight-commander.org))
* Text editor for the console (for example, mcedit, nano, vim). In the examples, we will use the editor built into Midnight Commander, mcedit, to avoid needing to look up exit commands for vim.

*When using MC, you don't need to install an editor, since the built-in one is enough. If an additional editor has been installed, the first time the [F4 Edit] command is executed, MC will prompt you to select the desired one. The example will use the built-in MC editor, which is called by pressing [F4] when a file is selected in the interface or using the mcedit <file name to create/open> command.*

> The quicker way is to do everything from the command line. [I want it quick!](#cli_manticore_docker)

#### Infrastructure deployment

We will conduct experiments with Manticore in a Docker container, as this is a popular cross-platform solution and is often used in an environment where Manticore is most in demand, although there are versions of the database for all popular operating systems.

*Those pros who already know how to work with docker can skip it until the container is launched. Well, the newcomers and I will go through the steps of starting from scratch.*

To begin, you must complete the following steps:
1. Download Docker Desktop for our platform from the website [https://www.docker.com/](https://www.docker.com/products/docker-desktop/):
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/znoiswsl193235rwisz0.png)
2. After installation, we need to grab the official Manticore image. In the top bar of the app, there's a search bar. Just type "ManticoreSearch" into that.
3. In the output, we have the "manticoresearch/manticore".
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49p82s7vwriwdzbzrg8e.png)
4. Click on the "pull" button, then switch to the images tab.
5. And then we select the new image we just downloaded and click "play".

In the window that pops up, you need to enter some extra settings:
- Name of the container: `manticore`.
- For the ports, let's just use the same port as the database for simplicity, which is `9306`.
- In the environment variables, set the variable `EXTRA` with the value `1`. This is required for running supplementary components that are very useful. Learn more about it [here](https://github.com/manticoresoftware/docker/tree/docker-6.2.12?tab=readme-ov-file#manticore-columnar-library-and-manticore-buddy).

And then click "Run"
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s8dii929ipyt6rvwa4s5.png)
Next, go back to the container tab. We'll find our container in the list of active containers. In the dropdown menu, there's an "Open in terminal" option. A window will pop up with a terminal that's directly connected to your container.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgwvslm6wp44xz416bsz.png)
Congrats, you've successfully installed Manticore Search docker image on your computer.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ay6rpr1gnsq43ijisa0.png)
<a id="cli_manticore_docker"></a>

> After messing around with the Docker Desktop interface for a while, you realize that the quickest way to get things done is through the command line.
> <code>docker run -e EXTRA=1 \-\-name manticore -p 9306:9306 -d manticoresearch/manticore</code>
> <code>docker exec -it manticore /bin/sh</code>

6. To make things easier, we'll be installing the Midnight Commander file manager inside the container:

```bash
apt update
apt install mc
mc
```
So, we updated the "apt" package manager, then we installed the "mc" file manager and launched it.
Now, your terminal should look like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ccv94rx948j3jf07qid2.png)

### First step. First table.

Alright, let's connect to the database and make our first table.

```bash
mysql -h0 -P9306
```
*Here is the `-h` flag for the host connection, set to `0` because we are trying to connect to localhost. Use the `-P` flag (note the uppercase P) for the port connection; we are using the internal port number.*

Let's create a table with an "info" field as text and a "value" field as an integer. Additionally, let's enhance this table with a stemmer for English words.

```sql
CREATE TABLE demo (info TEXT, value INT) morphology = 'stem_en';
Query OK, 0 rows affected (0.00 sec)
```
To see what fields were created when you created or altered a table column, use the `desc` command (it's like a "description").
```sql
DESC demo
+-------+-----------+------------------+
| Field | Type      | Properties       |
+-------+-----------+------------------+
| id    | bigint    |                  |
| info  | text      | indexed stored   |
| value | uint      |                  |
+-------+-----------+------------------+

3 rows in set (0.00 sec)
```
Also, you can check which stemming or lemmatizing algorithm is associated with the table:
```sql
SHOW TABLE demo SETTINGS;
+---------------+-----------------------+
| Variable_name | Value                 |
+---------------+-----------------------+
| settings      | morphology = stem_en  |
+---------------+-----------------------+

1 row in set (0.01 sec)
```
Let's add the data to the table. Below is an option to add one record at a time:
```sql
INSERT INTO demo (info, value) VALUES ('Walking down the street', 1);

Query OK, 1 row affected (0.01 sec)
```
and here's how to add records as a batch:
```sql
INSERT INTO demo (info, value) VALUES ('Walking along the embankment', 2), ('Walking the dog', 3), ('Reading a book', 4), ('Book read ', 5);

Query OK, 3 rows affected (0.00 sec)
```
Now let's check what we have written in the table:
```sql
SELECT * FROM demo;

+-----------------------+----------------------------------------------------+-------+
| id                    | info                                               | value |
+-----------------------+----------------------------------------------------+-------+
| 8217204862853578790   | Walking down the street                            |     1 |
| 8217204862853578791   | Walking along the embankment                       |     2 |
| 8217204862853578792   | Walking the dog                                    |     3 |
| 8217204862853578793   | Reading a book                                     |     4 |
| 8217204862853578794   | Book read                                          |     5 |
+-----------------------+----------------------------------------------------+-------+

5 rows in set (0.01 sec)
```
Let's search for a word that is close in meaning to the added ones:
```sql
SELECT * FROM demo WHERE match('read');

+---------------------+-----------------------------------+-------+
| id                  | info                              | value |
+---------------------+-----------------------------------+-------+
| 8217204862853578794 | Book read                         |     5 |
| 8217204862853578793 | Reading a book                    |     4 |
+---------------------+-----------------------------------+-------+

2 rows in set (0.01 sec)
```
You can also view the keyword for which the records were found, their number, documents, and more:
```sql
SHOW META;

+----------------+----------+
| Variable_name  | Value    |
+----------------+----------+
| total          | 2        |
| total_found    | 2        |
| total_relation | eq       |
| time           | 0.000    |
| keyword[0]     | read     |
| docs[0]        | 2        |
| hits[0]        | 2        |
+----------------+----------+

7 rows in set (0.01 sec)
```
To work with fields that are not involved in full-text search, attributes, you can use the classic SQL filtering statements:
```sql
SELECT * FROM demo WHERE value > 3;

+---------------------+-----------------------------------+-------+
| id                  | info                              | value |
+---------------------+-----------------------------------+-------+
| 8217204862853578794 | Book read                         |     5 |
| 8217204862853578793 | Reading a book                    |     4 |
+---------------------+-----------------------------------+-------+

2 rows in set (0.01 sec)
```
Deleting records can be done in the same way as the select queries:
```sql
DELETE FROM demo WHERE value = 5;

Query OK, 1 row affected (0.01 sec)

DELETE FROM demo WHERE match ('street');

Query OK, 1 row affected (0.01 sec)

DELETE FROM demo WHERE id = 8217204862853578791;

Query OK, 1 row affected (0.00 sec)

SELECT * FROM demo;

+---------------------+---------------------------------+-------+
| id                  | info                            | value |
+---------------------+---------------------------------+-------+
| 8217204862853578792 | Walking the dog                 |     3 |
| 8217204862853578793 | Reading a book                  |     4 |
+---------------------+---------------------------------+-------+

2 rows in set (0.00 sec)
```
Why don't you try adding and searching for some records? When you've finished, we can move on to the next thing.
Don't forget to disconnect:
```sql
exit;
```

Today that's all, next time we will see [how to change the word forms file in an existing table](/blog/mike-replace-update-wordforms/) and how to update our records.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xauhb2if3tck7xmdz98.JPG)