Match against "foo.bar" (with a full-stop/period) - mysql

I can search for rows with both foo and bar in the col1/col2 using match against:
SELECT col1, col2
FROM some_table
WHERE MATCH (col1,col2)
AGAINST ('+foo +bar' IN BOOLEAN MODE);
But suppose I want to search for the exact phrase "foo.bar" (with a full-stop in the middle). On the docs page for Boolean Full-Text Searches, it doesn't mention full-stop being an operator, so I thought I could use:
AGAINST ('+foo.bar' IN BOOLEAN MODE);
However, this returns the same results as:
AGAINST ('+foo.couldBeAnything' IN BOOLEAN MODE);
AGAINST ('+foo' IN BOOLEAN MODE);
AGAINST ('+foo.*' IN BOOLEAN MODE); #Note you would expect this to look for instances of foo. followed by something, rather than just the same as foo
.
Why isn't this working as I expect? and how can I match against for foo.bar?

I don't have a fulltext table readily available to test this out, but I believe this should work:
SELECT col1, col2
FROM some_table
WHERE MATCH (col1,col2)
AGAINST ('+\"foo.bar\"' IN BOOLEAN MODE);

To make this work, you need to suround your literal by a double quote: "bar.foo",
because the point is probably equivalent to or operator.

Related

MySql-5.1.40 fullText search doesn't work in MyISAM table

The MySQL version is 5.1.40
The table is MyISAM(only changed the table to MyISAM)
The type of table_column(name) is varchar
When I apply the fullText search, it doesn't work.
Below sql only return data 'eeee', will not return such as 'eeeefff' or 'ffeeee'
select name from test where match(name) against('eeee' in boolean mode);
MySQL's full text search lets you search for keywords beginning, but not ending, in a certain substring. So, to find all words beginning with eeee we can try:
SELECT name
FROM test
WHERE MATCH(name) AGAINST('eeee*' IN BOOLEAN MODE);

MySQL FULLTEXT search returns only exact match

I added a FULLTEXT index to a table like so:
ALTER TABLE TEST ADD FULLTEXT(name, descrip, notes);
The TEST table has 100 rows. I updated the descrip column with 'branch' in one row and 'Branches' in another row.
Then I run
SELECT * FROM TEST WHERE MATCH(name, descrip, notes) AGAINST ('branch' IN BOOLEAN MODE);
The result returned only rows that contain 'branch'. 'Branches' is not included in the result, even though it is comprised of the word that was searched. How to include 'Branches'? I want to avoid using LIKE.
In boolean mode you can use a wildcard:
AGAINST ('branch*' IN BOOLEAN MODE);
Here goes your query. You need to use wildcard.
SELECT * FROM TEST WHERE MATCH(name, descrip, notes) AGAINST ('branch*' IN BOOLEAN MODE);

How to use MATCH AGAINST in Mysql instead of LIKE

as everyone knows LIKE is too slow, but when I try to use MATCH AGAINST instead, its useless.
I need some operand that give the result such as LIKE '%part%' When "part" is part of the word not a complete word.
I have already tried
SELECT * FROM `table` WHERE MATCH (title) AGAINST ('*part*' IN BOOLEAN MODE)
SELECT * FROM `table` WHERE MATCH (title) AGAINST ('+*part*' IN BOOLEAN MODE)
and its not working
any solution?
You can only match words with a wildcard from the beginning of the word. As the documentation explains:
*
The asterisk serves as the truncation (or wildcard) operator. Unlike
the other operators, it is appended to the word to be affected. Words
match if they begin with the word preceding the * operator.

Full-stop/period operator in match against

I can search for all rows with foo in the col1/col2 using match against:
SELECT col1, col2
FROM some_table
WHERE MATCH (col1,col2)
AGAINST ('foo' IN BOOLEAN MODE);
But suppose I want to search for all rows with foo. (i.e. foo with a full-stop as the next character). On the docs page for Boolean Full-Text Searches, it doesn't mention full-stop being an operator, so I thought I could use either of these:
AGAINST ('foo.' IN BOOLEAN MODE);
AGAINST ('"foo."' IN BOOLEAN MODE);
AGAINST ('"foo\."' IN BOOLEAN MODE);
However, this returns the same results as:
AGAINST ('foo.couldBeAnything' IN BOOLEAN MODE);
AGAINST ('foo' IN BOOLEAN MODE);
AGAINST ('foo*' IN BOOLEAN MODE);
.
What is the . operator in this context? and how can I match-against foo.?
Note: I first asked this question about match-against foo.bar which led me to ask this follow up.
Full-stop, or indeed any punctuation, is treated like a space in a FULL-TEXT SEARCH, unfortunately this means there is no way to search for punctuation. The reasoning behind this is that text search is for finding "words" (which don't include punctuation).
To do such a search against punctuation, you could match against regular expressions, e.g. by using preg_match.

MySQL REGEXP usage within Boolean Match/Against

I have the following MySQL query:
SELECT title, description
FROM some_table
WHERE MATCH (title,description) AGAINST ('+denver (REGEXP "[[:<:]]colorado[s]*[[:>:]]")' IN BOOLEAN MODE);
the "regexp" here looks for a "complete word" colorado (with or without the ending "s").
I want to actually select only those rows that have ("denver") AND ("colorado" or "colorados"). But I cannot put a "+" for the REGEXP. I tried but got 0 results, although there are rows in the table that match the requirement.
Any ideas on how I can get the "+" to work within against using a REGEXP?
I am constructing this from within a PHP script where "denver" and "colorado" are values of variables I use to construct the select statement.
My PHP/MySQL script would look somewhat like this:
SELECT title, description
FROM some_table
WHERE MATCH (title,description) AGAINST ('+$var1 (REGEXP "[[:<:]]$var2[s]*[[:>:]]")' IN BOOLEAN MODE);
I don't think it's possible to combine regular expressions and MATCH ... IN BOOLEAN MODE. You need to use the syntax for writing boolean expressions.
Boolean Full-Text Searches
Try something like this:
SELECT title, description
FROM some_table
WHERE MATCH (title,description)
AGAINST ('+denver +(colorado colorados)' IN BOOLEAN MODE);