I usually use the custom search function after enabling FulltextSearchable . So in _config.php I would have
FulltextSearchable::enable(); Object::add_extension('NewsStory', "FulltextSearchable('Name,Content')");
replacing the name and contents with what DBField you want to search for. And each DataObject search has it in its class to enable search indexes (pretty sure that you need to add and run dev / build before enabling the extension and work only with MySQL).
static $create_table_options = array( 'MySQLDatabase' => 'ENGINE=MyISAM' );
then in my PageController I have my own functions searchForm and results.
Here is the search function, which returns a search form called $search in the template:
public function search() { if($this->request && $this->request->requestVar('Search')) { $searchText = $this->request->requestVar('Search'); }else{ $searchText = 'Search'; } $f = new TextField('Search', false, $searchText); $fields = new FieldList( $f ); $actions = new FieldList( new FormAction('results', 'Go') ); $form = new Form( $this, 'search', $fields, $actions );
and here is the user-defined function results for processing requests ...
function results($data, $form, $request) { $keyword = trim($request->requestVar('Search')); $keyword = Convert::raw2sql($keyword); $keywordHTML = htmlentities($keyword, ENT_NOQUOTES, 'UTF-8'); $pages = new ArrayList(); $news = new ArrayList(); $mode = ' IN BOOLEAN MODE';
I add all the page classes that I want to find that extend SiteTree in the $siteTreeClasses , and news pieces can be copied for any other DataObject that is required for the search.
I am not saying that this is the best solution, and it certainly can be improved, but it works for me, and it can be a good expression.