FULLTEXT
FULLTEXT is a type of index in SQL used to enhance the speed of text-based searches in large strings of text. It aids in performing complex word-based searches more efficiently, and supports advanced search operations like natural language search, boolean search, or query expansion. This indexing technique is applicable on CHAR, VARCHAR, or TEXT type column in MySQL. FULLTEXT deliver search results based on the relevance and significance of the data.
Example
Output
Explanation
In the above example, a FULLTEXT index is built on the ‘title’ and ‘content’ columns of the ‘Article’ table. As a result, the use of FULLTEXT allows you to perform text search queries on these fields. The MATCH() function is used with AGAINST() to search for rows that contain the word ‘sample’ in either the title or the content. The ‘IN NATURAL LANGUAGE MODE’ option specifies that the search is to be performed using the natural language (non-boolean) full-text search mode. In the output, the query returns the row where the word ‘sample’ appears either in the ‘title’ or ‘content’.
Example
Output
Explanation
In the provided SQL Server example, a table named ‘Blogs’ is created with ‘id’ as the primary key and ‘contents’ as the body of each record. Three records are inserted into this table.
A full-text catalog ‘ftCatalog’ is created with a full-text index on the ‘contents’ column of the table. This enables full-text search on the ‘contents’ column.
The CONTAINS
keyword is used in the SELECT
query to search within the ‘contents’ column for the term ‘database’. The output of this query displays the records which contain ‘database’ in their ‘contents’ field.
Example
Output
Explanation
In this example, a full-text search is used in SQLite to find the rows in which the author’s name starts with ‘F’. The MATCH
keyword is used with the books
table to perform the full text search.
An FTS4 table named ‘books’ is created with ‘title’ and ‘author’ as columns. Two rows are inserted into the ‘books’ table. The select query finds the rows where the author’s name starts with ‘F’. The result is the row with the ‘The Great Gatsby’ by ‘F. Scott Fitzgerald’.