mysql fulltext multiple words from one form input? - mysql

I've heared alot of similar discussion but I havent seen a direct solution.
SELECT * FROM patient_db WHERE
MATCH ( Name, id_number ) AGAINST ('%$term%' IN BOOLEAN MODE);
Isn't there something simple around my '%$term%' I need to do to enable multiple-word searching?

Unfortunately, there is no way to directly say, "I want one of these n words" in a MySQL fulltext query. Your only real option is
SELECT * FROM patient_db WHERE
MATCH ( Name, id_number ) AGAINST ('%$term%' IN BOOLEAN MODE)
OR MATCH ( Name, id_number ) AGAINST ('%$term2%' IN BOOLEAN MODE)
OR MATCH ( Name, id_number ) AGAINST ('%$term3%' IN BOOLEAN MODE)
;
Just curious, but why are you searching a column named id_number for text?

Related

query that returns rows that do not contain a word in MySql

I am trying to make a query where I select all the rows that do not contain a specific word, for this I have a fulltext type index in this column, try the following bolt works:
SELECT *
FROM products
WHERE MATCH(title) AGAINST(' -Dolo' IN BOOLEAN MODE)
So how can I perform this search?
If I have understood you correctly you want to find all the rows from the table that do not contain a word'Dolo'.
Well you can use NOT operator for that.
SELECT *
FROM products
WHERE NOT MATCH(title) AGAINST('Dolo');
Here is a DEMO.
Also, you can use it like this(because as the OP has asked: "if the whole word is "dolorem", would this query work?"):
SELECT title as Title
, MATCH(title) AGAINST('Dolo*' IN BOOLEAN MODE) as Score
FROM products
WHERE MATCH(title) AGAINST('Dolo*' IN BOOLEAN MODE) = 0;
* is a wildcard.
Other signs are described here: https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html
Here is the DEMO for the second example.

Mysql MATCH AGAINST options: exact phrase along with extra word

I am trying to enhance a third part (awesome) django framework named django-watson and I currently need to make my way through a so far unknown mysql option, the MATCH (...) AGAINST (...).
So, I already know how to retrieve an exact phrase, which is doing:
SELECT *
FROM patient_db
WHERE MATCH ( Name, id_number )
AGAINST ('"exact phrase"' IN BOOLEAN MODE);
An I also know how to retrieve results that contain words from a list:
SELECT *
FROM patient_db
WHERE MATCH ( Name, id_number )
AGAINST ('+keyword1 +keyword2' IN BOOLEAN MODE);
But I need a third option, which is mixing the two above quoted. I'd like to do something like the google search: "exact phrase" +keyword1 +keyword2.
_PS: when I search for "exact phrase" -keyword1 it works exactly as desired _
Any Ideas?
Try this.
SELECT *
FROM patient_db
WHERE MATCH ( Name, id_number )
AGAINST ('+keyword1 +keyword2' IN BOOLEAN MODE)
OR MATCH ( Name, id_number )
AGAINST ('"exact phrase"' IN BOOLEAN MODE)

MySQL Full-text search using OR

I have a MySQL database and i want to search using match.
I use the following query for one phrase.
SELECT
text, date, type
FROM
`test`
WHERE
MATCH (`TEXT`) AGAINST ('+word1 +word2' IN BOOLEAN MODE)
;
But i cant find a way to search '+word1 +word2' OR '+word3 +word4'
Any idea?
This is the solution:
MATCH (`TEXT`) AGAINST ('(+word1 +word2) (+word3 +word4)' IN BOOLEAN MODE)

Match statement spaced words return results from multiple columns

In this situation, I want to find all records that contain the name steve in one column and email#email.com in another. I know Im missing an operator, but i dont know which
SELECT firstname,lastname,middlename,company_name,
primary_emailaddress,alternate_emailaddress,personal_address_line1,
personal_address_line2,personal_address_city,facebook_username,
twitter_username,googleplus_username,linkedin_username,
personal_website_url,birthday_month,notes,personal_address_zipcode,
company_address_zipcode,home_phonenumber,company_phonenumber,
cell_phonenumber,birthday_day,birthday_year,hash,image_file
FROM contacts
WHERE (
MATCH(
firstname,lastname,
primary_emailaddress,alternate_emailaddress,personal_address_line1,
personal_address_city,company_name,
company_address_line1,company_address_city,
facebook_username,twitter_username,googleplus_username,linkedin_username,
personal_website_url
)
AGAINST ('Steve email#email.com' IN BOOLEAN MODE))
Match is faster than a like comparison. I think you can do it twice in a where clause:
SELECT firstname,lastname,middlename,company_name,
primary_emailaddress,alternate_emailaddress,personal_address_line1,
personal_address_line2,personal_address_city,facebook_username,
twitter_username,googleplus_username,linkedin_username,
personal_website_url,birthday_month,notes,personal_address_zipcode,
company_address_zipcode,home_phonenumber,company_phonenumber,
cell_phonenumber,birthday_day,birthday_year,hash,image_file
FROM contacts
WHERE MATCH (firstname) AGAINST ('Steve' IN BOOLEAN MODE) > 0 and
MATCH (primary_emailaddress, alternate_emailaddress)
AGAINST ('email#email.com' IN BOOLEAN MODE) > 0;
Unless you are really looking through every field, (i.e. John Stevenson would be considered a match on 'Steve') you can do this much simpler...
select *
from contacts
where firstname like '%Steve%'
and (primary_emailaddress like '%email#email.com%' or alternate_emailaddress like '%email#email.com%')

MySQL full-text search: "proves" gets "proves" but not "prove"

Please show me where I'm wrong with this query:
SELECT * FROM `pages` WHERE MATCH ( abstrak) AGAINST ('+"prove"' IN BOOLEAN MODE)
doesn't get 'proves', when I want is it gets 'proves'.
Try this:
SELECT * FROM `pages` WHERE MATCH ( abstrak) AGAINST ('prove*' IN BOOLEAN MODE)
This would match all words that start with prove, including proves.
More info at:
http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html