AJAX response action for search autocomplete/results.

Returns

array Returns an array detailing the symbol and its metadata.

Source

						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'));
	}