Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FULL TEXT SEARCH in cakephp ? any example

I am using ordinary search functionality in my business controller . but now need to implement FULL TEXT SEARCH with paginate can any one give idea or sample ? I am using MySQL with MyISAM tabes

and this my table structure, fields marked bold are need to use in search

CREATE TABLE IF NOT EXISTS businesses ( 
  id bigint(20) unsigned NOT NULL AUTO_INCREMENT, 
  created date NOT NULL, 
  modified datetime NOT NULL, 
  user_id bigint(20) NOT NULL, 
  slug varchar(255) NOT NULL, 
  **`name` varchar(255) NOT NULL,** 
  **street_name varchar(255) DEFAULT NULL,** 
  **shopping_center varchar(255) DEFAULT NULL,** 
  state_id int(10) NOT NULL, 
  suburb_id int(10) NOT NULL, 
  zip_code varchar(12) DEFAULT NULL, 
  website varchar(250) DEFAULT NULL, 
  email varchar(255) DEFAULT NULL, 
  phone_no varchar(255) NOT NULL, 
  mobile_no varchar(255) DEFAULT NULL, 
  fax varchar(255) DEFAULT NULL, 
  is_active tinyint(1) NOT NULL DEFAULT '1', 
  PRIMARY KEY (id) 
) ENGINE=MyISAM  DEFAULT CHARSET=latin1; 
like image 811
AnNaMaLaI Avatar asked May 31 '11 07:05

AnNaMaLaI


1 Answers

After you have created your FULLTEXT indices it's not different at all from normal paginate conditions, you just need to construct your SQL a little more manually and most importantly escape the user input manually.

$query = 'foobar'; // the user input to search for
$escapedQuery = $this->Business->getDataSource()->value($query);

$this->paginate['conditions'] = array("MATCH (Business.name) AGAINST ($escapedQuery)");
$businesses = $this->paginate();
like image 111
deceze Avatar answered Nov 23 '22 02:11

deceze