Mike: learning: First steps

anstalf

Mike

Posted on June 5, 2024

Mike: learning: First steps

About me

Image description
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:

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)
  • 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 command.

The quicker way is to do everything from the command line. I want it quick!

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/: Image description
  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
  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.

And then click "Run"
Image description
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
Congrats, you've successfully installed Manticore Search docker image on your computer.
Image description

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.
docker run -e EXTRA=1 --name manticore -p 9306:9306 -d manticoresearch/manticore
docker exec -it manticore /bin/sh

  1. To make things easier, we'll be installing the Midnight Commander file manager inside the container:
apt update
apt install mc
mc
Enter fullscreen mode Exit fullscreen mode

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

First step. First table.

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

mysql -h0 -P9306
Enter fullscreen mode Exit fullscreen mode

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.

CREATE TABLE demo (info TEXT, value INT) morphology = 'stem_en';
Query OK, 0 rows affected (0.00 sec)
Enter fullscreen mode Exit fullscreen mode

To see what fields were created when you created or altered a table column, use the desc command (it's like a "description").

DESC demo
+-------+-----------+------------------+
| Field | Type      | Properties       |
+-------+-----------+------------------+
| id    | bigint    |                  |
| info  | text      | indexed stored   |
| value | uint      |                  |
+-------+-----------+------------------+

3 rows in set (0.00 sec)
Enter fullscreen mode Exit fullscreen mode

Also, you can check which stemming or lemmatizing algorithm is associated with the table:

SHOW TABLE demo SETTINGS;
+---------------+-----------------------+
| Variable_name | Value                 |
+---------------+-----------------------+
| settings      | morphology = stem_en  |
+---------------+-----------------------+

1 row in set (0.01 sec)
Enter fullscreen mode Exit fullscreen mode

Let's add the data to the table. Below is an option to add one record at a time:

INSERT INTO demo (info, value) VALUES ('Walking down the street', 1);

Query OK, 1 row affected (0.01 sec)
Enter fullscreen mode Exit fullscreen mode

and here's how to add records as a batch:

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)
Enter fullscreen mode Exit fullscreen mode

Now let's check what we have written in the table:

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)
Enter fullscreen mode Exit fullscreen mode

Let's search for a word that is close in meaning to the added ones:

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)
Enter fullscreen mode Exit fullscreen mode

You can also view the keyword for which the records were found, their number, documents, and more:

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)
Enter fullscreen mode Exit fullscreen mode

To work with fields that are not involved in full-text search, attributes, you can use the classic SQL filtering statements:

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)
Enter fullscreen mode Exit fullscreen mode

Deleting records can be done in the same way as the select queries:

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)
Enter fullscreen mode Exit fullscreen mode

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:

exit;
Enter fullscreen mode Exit fullscreen mode

Today that's all, next time we will see how to change the word forms file in an existing table and how to update our records.

Image description

💖 💪 🙅 🚩
anstalf
Mike

Posted on June 5, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related