w3resource

MySQL Boolean Mode Full-Text Search Exercise with Solution


Boolean Mode Full-Text Search

Write a MySQL query to perform a full-text search in boolean mode on the "Content" column for the term "SQL" including the "+" operator.

Solution:

-- Perform a full-text search in BOOLEAN MODE for articles that must include the term 'SQL'.

-- Select all columns from the Articles table where the Content column includes the term 'SQL'.
SELECT * 
-- Specify the table from which to retrieve the data.
FROM Articles

-- Use the MATCH...AGAINST clause with BOOLEAN MODE to perform a full-text search.
-- The '+' operator before 'SQL' ensures that the term 'SQL' must be present in the results.
WHERE MATCH(Content) AGAINST('+SQL' IN BOOLEAN MODE);

Explanation:

  • Purpose of the Query:
    • To ensure that only articles containing the term "SQL" are returned.
    • Demonstrates how to use BOOLEAN MODE to enforce term inclusion.
  • Key Components:
    • +SQL : The plus sign indicates the term must be present.
    • IN BOOLEAN MODE : Specifies that the search should use boolean logic.
  • Real-World Application:
    • Beneficial for search features where certain keywords are mandatory in the result set.

Notes:

  • Boolean mode allows the use of operators for more refined searches.
  • Verify that full-text indexes support BOOLEAN MODE.

For more Practice: Solve these Related Problems:

  • Write a MySQL query to perform a boolean mode full-text search on the "Content" column requiring the term "optimization" and excluding the term "deprecated".
  • Write a MySQL query to execute a boolean mode full-text search on the "Content" column using a combination of mandatory and optional terms.
  • Write a MySQL query to perform a boolean full-text search on the "Content" column where at least one out of several synonyms must appear.
  • Write a MySQL query to search the "Content" column in boolean mode using a quoted phrase to enforce proximity between words.

Go to:


PREV : Full-Text Search on Multiple Columns.
NEXT : Full-Text Search with Relevance Ranking.

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.