0

I have following mysql table structure : http://sqlfiddle.com/#!9/d36f69/2

CREATE TABLE IF NOT EXISTS `subcat` (
  `id` int(11) DEFAULT '0',
  `subCatName` varchar(255) NOT NULL,
  `Keywords` varchar(255) DEFAULT NULL,
  KEY `Keywords` (`Keywords`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Following are two records :

id  subCatName  Keywords
1   Plastic     baby toys, bag, basket
2   Metal   metal finish, box cover

Now i want to search record using keywords field. Suppose i enter

"baby toys products"

Then you can see that in keywords field there is words "baby toys". So that subcat record should be return in search query. Here you can see that "products" is not matched in keywords but only two words are matched. Then still first matched record should return in result.

How can we do it ?

user3264863
  • 278
  • 4
  • 15
  • 2
    If you want this type of search you should normalize you keywors column in separated rows.. – ScaisEdge Oct 11 '16 at 06:29
  • You have to use mysql's built-in full text search functionality or use an external full text search library, such as sphinx – Shadow Oct 11 '16 at 06:32

1 Answers1

0

split the keywords to different term, and also the searching words to different terms, then use wildcard, like 'select * from subcat where keywords like '%baby%'' or use FTS lib directly.