Exemplo n.º 1
0
 /**
  * AJAX response action for search autocomplete/results.
  *
  * @return array Returns an array detailing the symbol and its metadata.
  */
 public function query()
 {
     $this->_render['type'] = 'json';
     $query = $this->request->params['query'];
     $conditions = array();
     // If the leading character is upper-case, only search models.
     if (preg_match('/^[A-Z]/', $query)) {
         $conditions['type'] = 'class';
     }
     // If it contains a '$', only search properties.
     if (preg_match('/\\$/', $query)) {
         $query = str_replace('$', '', $query);
         $conditions['type'] = 'property';
     }
     // If it contains parens, only search methods.
     if (preg_match('/[\\(\\)]/', $query)) {
         $query = str_replace('(', '', $query);
         $query = str_replace(')', '', $query);
         $conditions['type'] = 'method';
     }
     $conditions['name'] = array('like' => '%' . $query . '%');
     $results = Symbols::find('all', array('conditions' => $conditions));
     // Lack of results might be due to no data in db...
     if (count($results) < 1) {
         if (Symbols::find('count') == 0) {
             $results = array('error' => 'Please run `$ li3 harvest` to enable search.');
         }
     }
     $this->set(compact('results'));
 }
Exemplo n.º 2
0
    /**
     * Drops, then re-creates the Sqlite3 tables used for searching.
     *
     * @return void
     */
    protected function _readyTables()
    {
        $dropSql = 'DROP TABLE IF EXISTS `symbols`';
        Symbols::connection()->invokeMethod('_execute', array($dropSql));
        $createSql = 'CREATE TABLE IF NOT EXISTS `symbols` (
			`id` INTEGER NOT NULL PRIMARY KEY,
			`name` VARCHAR (255) NOT NULL,
			`type` VARCHAR (255) NOT NULL,
			`class` TEXT NOT NULL,
			`description` TEXT NOT NULL
		);';
        Symbols::connection()->invokeMethod('_execute', array($createSql));
    }