Croogo Full Text Search
Introduction
Croogo currently doesn't have full text search but with this action you can add full text capabilities to your Croogo installation. This is not guaranteed to work after Croogo 1.1, and hopefully full text search is implemented into the core. Currently this implementation allows you to search blog posts.
Requirements
- Croogo 1.1
- MySQL
Example
The search action must go into the nodes controller. You will need to make a search form that's url points to the nodes controller and the search method. In this implementation I am using the "GET" method and it's reflected in the search action. In your search.ctp view you can use the CakePHP text helper to highlight the search term and display an excerpt instead of the full post. Below is an example:
<p><?php echo $text->highlight($text->excerpt(strip_tags($this->element('node_body', array('node' => $node))), $q, 200, '...'), $q); ?></p>
Code
function search () {
// Import sanitize library
App::import('Core', array('Sanitize'));
$query = mysql_escape_string(Sanitize::html($this->params['url']['q']));
$this->paginate['Node']['order'] = 'Node.id DESC';
$this->paginate['Node']['limit'] = Configure::read('Reading.nodes_per_page');
$this->paginate['Node']['conditions'] = array(
'Node.type' => 'blog',
'Node.status' => 1,
"MATCH(Node.title, Node.body) AGAINST('{$query}' IN BOOLEAN MODE)"
);
$this->paginate['Node']['contain'] = array(
'User',
'Meta',
'Comment',
'Term' => array('Vocabulary')
);
$this->Node->recursive = 0;
$this->set('nodes', $this->paginate());
$this->set('q', $query);
$this->set('title', "Search results for {$query}");
}
If you have any questions or comments drop me a line below and I will try to get back to you as soon as possible.
Last Updated: December 9th 2009, 6:26am
Download: Croogo Full Text Search

0 Comments