Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL fulltext search - Only results that contain all words

Tags:

mysql

With the following query I get results that contain the words "International" AND "Shipping" and I also get results that contain "International" OR "Shipping". What can I do to ensure that the results contain both words and not just one of them?

Any help would be greatly appreciated, thanks!

SELECT client_company,client_description,client_keywords
FROM tb_clients
WHERE
MATCH (client_company,client_description,client_keywords)
AGAINST ('International Shipping') > 0
LIMIT 10
like image 205
mike Avatar asked Feb 17 '10 17:02

mike


People also ask

Does MySQL have full text search?

MySQL has support for full-text indexing and searching: A full-text index in MySQL is an index of type FULLTEXT . Full-text indexes can be used only with InnoDB or MyISAM tables, and can be created only for CHAR , VARCHAR , or TEXT columns.

How do you perform a full-text case sensitive search in MySQL?

To perform a case-sensitive full-text search, use a case-sensitive or binary collation for the indexed columns. For example, a column that uses the utf8mb4 character set of can be assigned a collation of utf8mb4_0900_as_cs or utf8mb4_bin to make it case-sensitive for full-text searches.

How do I create a full text search in MySQL?

The basic query format of full-text searches in MySQL should be similar to the following: SELECT * FROM table WHERE MATCH(column) AGAINST(“string” IN NATURAL LANGUAGE MODE); When MATCH() is used together with a WHERE clause, the rows are automatically sorted by the highest relevance first.

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

Like uses wildcards only, and isn't all that powerful. Full text allows much more complex searching, including And, Or, Not, even similar sounding results (SOUNDEX) and many more items.


1 Answers

Add a + in front of every required word and use IN BOOLEAN MODE.

11.8.2. Boolean Full-Text Searches

In implementing this feature, MySQL uses what is sometimes referred to as implied Boolean logic, in which

 + stands for AND
 - stands for NOT
  [no operator] implies OR
like image 167
Pekka Avatar answered Sep 30 '22 20:09

Pekka