Version 3 end of life
This version of Silverstripe CMS will not recieve any additional bug fixes or documentation updates. Go to documentation for the most recent stable version.

FulltextSearchable

Fulltext search allows advanced search criteria for searching words within a text based data column. While basic Fulltext search can be achieved using the built-in MySQLDatabase class a more powerful wrapper for Fulltext search is provided through a module.

[notice] See the FulltextSearch Module. This module provides a high level wrapper for running advanced search services such as Solr, Lucene or Sphinx in the backend rather than MySQL search. [/notice]

Adding Fulltext Support to MySQLDatabase

The MySQLDatabase class defaults to creating tables using the InnoDB storage engine. As Fulltext search in MySQL requires the MyISAM storage engine, any DataObject you wish to use with Fulltext search must be changed to use MyISAM storage engine.

You can do so by adding this static variable to your class definition:

	<?php

	class MyDataObject extends DataObject {

		private static $create_table_options = array(
			'MySQLDatabase' => 'ENGINE=MyISAM'
		);
	}

[alert] The SearchForm and FulltextSearchable API's are currently hard coded to be specific to Page and File records and cannot easily be adapted to include custom DataObject instances. To include your custom objects in the default site search, have a look at those extensions and modify as required. [/alert]

Fulltext Filter

SilverStripe provides a FulltextFilter which you can use to perform custom fulltext searches on DataLists.

Example DataObject:

	class SearchableDataObject extends DataObject {
		
		private static $db = array(
			"Title" => "Varchar(255)",
			"Content" => "HTMLText",
		);

		private static $indexes = array(
			'SearchFields' => array(
				'type' => 'fulltext',
				'name' => 'SearchFields',
				'value' => '"Title", "Content"',
			)
		);

		private static $create_table_options = array(
			'MySQLDatabase' => 'ENGINE=MyISAM'
		);

	}
	SearchableDataObject::get()->filter('SearchFields:fulltext', 'search term');

field instead of the index.

API Documentation