silverstripe-framework/docs/en/02_Developer_Guides/12_Search/02_FulltextSearch.md
Michael Pritchard fdbd899766 DOC Update SilverStripe to Silverstripe CMS
- Remaining Developer Guides and Upgrading
- SilverStripe in a namespace or api has not been change
- To keep PRs easier no formatting was changed

Update merge conflics with two files

Update Silverstripe Ltd, Silverstripe Cloud and Silverstripe CMS

Silverstripe CMS Ltd > Silverstripe Ltd
Silverstripe CMS Platform > Silverstripe Cloud
Silverstripe CMS Framework > Silverstripe CMS

Resolve merge conflict

Remove Framework from Silverstripe CMS Framework

- 3 files

Change SilverStripe CMS to Silverstripe CMS
2021-07-30 13:54:15 +01:00

2.9 KiB

title summary icon
Fulltext Search Fulltext search allows sophisticated searching on text content. search

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:

use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Connect\MySQLSchemaManager;

class MyDataObject extends DataObject 
{
    private static $create_table_options = [
        MySQLSchemaManager::ID => 'ENGINE=MyISAM'
    ];
}

The FulltextSearchable extension will add the correct Fulltext indexes to the data model.

[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 CMS provides a FulltextFilter which you can use to perform custom fulltext searches on DataLists.

Example DataObject:

use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Connect\MySQLSchemaManager;

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

    private static $indexes = [
        'SearchFields' => [
            'type' => 'fulltext',
            'columns' => ['Title', 'Content'],
        ]
    ];

    private static $create_table_options = [
        MySQLSchemaManager::ID => 'ENGINE=MyISAM'
    ];

}

Performing the search:

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

If your search index is a single field size, then you may also specify the search filter by the name of the field instead of the index.

API Documentation