Gabriel
Gabriel

Reputation: 229

Searching using more than 1 keywords, on more than 1 fields using PHP & MySQL

I would like to have a search engine using PHP and MySQL to perform searches like this:

I will search for bumblebee camaro, in about 3 fields in tables.

I want to have results that return rows with both texts (having bumblebee and camaro) and also return the same result if I search for bumblebee cam.

I was using MATCH AGAINST IN BOOLEAN MODE, but the result was record with bumblebee, record with bumblebee and camaro.

I don't want records with only bumblebee text, only the second one. How to do that?

My SQL was: MATCH (field1,field2,field3) AGAINST('+bumblebee cam' IN BOOLEAN MODE)

Thanks for the response in advance!

Btw, I did try to split the keyword, but it was not returning the correct answer, because somehow the word bumblebee from the field1, and camaro from the field2, if i split it. it will show record the one that i dont need

Upvotes: 0

Views: 80

Answers (1)

Wiram Rathod
Wiram Rathod

Reputation: 1919

MATCH (field1,field2,field3) AGAINST ('bumblebee cam' IN BOOLEAN MODE)

would search for one of the words

MATCH (field1,field2,field3) AGAINST ('+bumblebee +cam' IN BOOLEAN MODE)

would search both words

MATCH (field1,field2,field3) AGAINST ('-bumblebee  +cam' IN BOOLEAN MODE)

would search Term without Search

just split the words and build it with using + - | , whatever needed.

check documentation on : http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

Upvotes: 1

Related Questions