Dino Geek, try to help you

How to do full text search in MariaDB?


In order to perform a full text search in MariaDB, you can leverage full text indexes, which enable the server to perform natural language searches, boolean text searches, or query expansion.

Here is a very basic example of how to use full text search in MariaDB.

1. First, full text indexes need to be defined on the table. You can either create a full text index while creating a table or alter an existing table to add a full text index.

```
CREATE TABLE articles ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, title VARCHAR, body TEXT, FULLTEXT (title,body)
) ENGINE=InnoDB;
```

or you can alter an existing table:

```
ALTER TABLE articles ADD FULLTEXT;
```

1. Once the full text index is created, you can use the MATCHAGAINST syntax in your SELECT statement to perform full text searches.

```
SELECT * FROM articles
WHERE MATCH (title,body) AGAINST (‘your search term’);
```

The above example will return the rows where ‘your search term’ is found in the ‘title’ or ‘body’ field of the ‘articles’ table.

There are several modes available for full text search like ‘IN NATURAL LANGUAGE MODE’, ‘IN BOOLEAN MODE’, ‘WITH QUERY EXPANSION’.

You can use them like this:

```
SELECT * FROM articles
WHERE MATCH (title,body) AGAINST (‘your search term’ IN NATURAL LANGUAGE MODE);

SELECT * FROM articles
WHERE MATCH (title,body) AGAINST (‘your search term’ IN BOOLEAN MODE);

SELECT * FROM articles
WHERE MATCH (title,body) AGAINST (‘your search term’ WITH QUERY EXPANSION);
```

Remember that full text search works best with large sets of data. It might not return correct results when used with small sets of data.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use