Thursday, July 5, 2007

Boolean Full-Text Searches

Full-text searching is performed using MATCH() ... AGAINST syntax. MATCH() takes a comma-separated list that names the columns to be searched. AGAINST takes a string to search for, and an optional modifier that indicates what type of search to perform. The search string must be a literal string, not a variable or a column name.

Interesting Full Text searches for web developers can be Boolean Full-Text Searches

The following examples demonstrate some search strings that use boolean full-text operators:

'apple banana'
Find rows that contain at least one of the two words.

'+apple +juice'
Find rows that contain both words.

'+apple macintosh'
Find rows that contain the word “apple”, but rank rows higher if they also contain “macintosh”.

'+apple -macintosh'
Find rows that contain the word “apple” but not “macintosh”.

'+apple ~macintosh'
Find rows that contain the word “apple”, but if the row also contains the word “macintosh”, rate it lower than if row does not. This is “softer” than a search for '+apple -macintosh', for which the presence of “macintosh” causes the row not to be returned at all.

The + and - operators indicate that a word is required to be present or absent, respectively, for a match to occur. Thus, this query retrieves all the rows that contain the word “MySQL” but that do not contain the word “YourSQL”.

reference : http://dev.mysql.com/doc/refman/4.1/en/fulltext-boolean.html

No comments: