Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL fulltext search Boolean mode confusion

I'm getting a bit confused when trying to set up a search utilizing fulltext search in boolean mode. Here is the query I'm using:

$query = "SELECT *,

       MATCH(title) AGAINST('$q' IN BOOLEAN MODE) AS score

       FROM results

       WHERE MATCH(title) AGAINST('$q' IN BOOLEAN MODE)

       ORDER BY score DESC";

When I run a search for +divorce+refinance, the results returned are:

1) Divorce: Paying Off Spouse = Rate/Term Refinance
2) Divorce - What to Look Out For Regarding Divorced Borrowers

Am I right in thinking that the second result should not be appearing, as it does not have both words? If not, how can I create that functionality?

like image 784
Martin Hunt Avatar asked Apr 06 '12 18:04

Martin Hunt


People also ask

What is Boolean mode in MySQL?

A Boolean search mode is an additional form of full-text search in MySQL. It is more word-driven than the natural language search that means it searches for words instead of the concept.

What is advantage of fulltext over like for performing text search in MySQL?

Using the LIKE operator gives you 100% precision with no concessions for recall. A full text search facility gives you a lot of flexibility to tune down the precision for better recall. Most full text search implementations use an "inverted index".

Does MySQL support Boolean?

MySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT). When you create a table with a boolean data type, MySQL outputs data as 0, if false, and 1, if true.

What is fulltext key in MySQL?

Full-text indexes are created on text-based columns ( CHAR , VARCHAR , or TEXT columns) to speed up queries and DML operations on data contained within those columns. A full-text index is defined as part of a CREATE TABLE statement or added to an existing table using ALTER TABLE or CREATE INDEX .


1 Answers

Maybe I am mistaken, but if you search this string +divorce+refinance you get a weird result. If you want to search both words, your should search for +divorce +refinance (with a space between).

I tested it and it returns only one row:

Divorce: Paying Off Spouse = Rate/Term Refinance
like image 172
Tchoupi Avatar answered Oct 21 '22 07:10

Tchoupi