Given a table named Show
For this to work, a fulltext index on the Title column must be available: Full-text search is a technique that enables you to search for records that might not perfectly match the search criteria. Full-text searches in MySQL are performed when certain indexes are in use and those indexes have many unique nuances including the following:
A FULLTEXT index is a special type of index that finds keywords in the text instead of comparing the values to the values in the index. Although FULLTEXT searching is different from other types of matching, do note that you can have a BTREE index and a FULLTEXT index on the same column at the same time – they will not conflict because they are suited for different purposes. Full-Text Search TypesWhen running full-text searches in MySQL, keep in mind that there are three search types to choose from:
Full-Text Searches with the Natural Language Search ModeA natural language search mode, as noted above, is enabled by default or when the IN NATURAL LANGUAGE MODE modifier is specified. This mode performs a natural language search against a given text collection (one or more columns). The basic query format of full-text searches in MySQL should be similar to the following:
When MATCH() is used together with a WHERE clause, the rows are automatically sorted by the highest relevance first. To search for an exact string, enclose it with double quotes. Full-Text Searches with the Query Expansion ModeFull-text searches also support the query expansion mode. Such a search mode is frequently used when the user relies on implied knowledge – for example, the user might search for “DBMS” hoping to see both “MongoDB” and “MySQL” in the search results. The reason why the user might be able to rely on some implied knowledge when using such a search mode is pretty simple – a full-text search with the query expansion mode works by performing the search twice: the second search phrase is the first search phrase concatenated with a few most relevant entries from the first search. That means that, for example, if in the first search one of the rows would contain the word “DBMS” and the word “MySQL”, the second search would find the entries that would include the word “MySQL” even if they do not contain “DBMS”. The query format that would use the query expansion mode would look like so:
Full-text Searches Using the Boolean ModeThe boolean mode is perhaps one of the most interesting things that MySQL full-text search has to offer. This mode has many caveats unique to it because it allows you to expand the search capabilities using boolean operators. When the boolean mode is in use, certain characters can have special meaning at the beginning or end of words. For example:
These operators allow you to expand the functionality of the search: for example, if you would want to retrieve all rows that contain the word “Demo”, but not “Demo2”, you could use a query like so:
You can also use double quotes together with single quotes like so:
Full-Text Search GotchasBefore using full-text search in MySQL, do keep in mind that the search does have a few “gotchas”:
|