mariadbMariadb fulltext search example
Mariadb fulltext search is a powerful search feature that allows you to search for words and phrases within a database. Here is an example of how to use it:
CREATE TABLE articles (
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
body TEXT NOT NULL,
FULLTEXT (title,body)
);
INSERT INTO articles (title, body) VALUES
('How to use Mariadb fulltext search', 'Mariadb fulltext search is a powerful search feature that allows you to search for words and phrases within a database.');
SELECT * FROM articles
WHERE MATCH (title,body) AGAINST ('Mariadb fulltext search');
Output example
id title body
1 How to use Mariadb fulltext search Mariadb fulltext search is a powerful search feature that allows you to search for words and phrases within a database.
The example code above creates a table called articles with two columns, title and body. The FULLTEXT keyword is used to create a fulltext index on the title and body columns. Then, an article is inserted into the table. Finally, a query is executed to search for the phrase Mariadb fulltext search in the title and body columns. The output of the query is the article that was inserted.
Code explanation
CREATE TABLE articles: creates a table calledarticleswith two columns,titleandbody.FULLTEXT (title,body): creates a fulltext index on thetitleandbodycolumns.INSERT INTO articles: inserts an article into the table.SELECT * FROM articles: executes a query to search for the phraseMariadb fulltext searchin thetitleandbodycolumns.
Helpful links
More of Mariadb
- How to use window functions in Mariadb?
- How to view Mariadb logs?
- What type to use for a year in Mariadb?
- How to use the WITH clause in Mariadb?
- How to list users in Mariadb?
- How to work with XML in Mariadb?
- How to use xtrabackup in Mariadb?
- How to change wait_timeout in Mariadb?
- How to use variables in Mariadb?
- How to check version of Mariadb?
See more codes...