8

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; 

1 Answer 1

10

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();
3
  • If I need to used multiple fields such as name and street_name and shopping_center ???
    – AnNaMaLaI
    Commented May 31, 2011 at 7:17
  • 2
    Read the documentation for MATCH ... AGAINST and construct your indices and queries accordingly.
    – deceze
    Commented May 31, 2011 at 7:19
  • Yes got it . Thanks i find a solution
    – AnNaMaLaI
    Commented May 31, 2011 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.