这是未经测试的代码,但我刚刚查看了 sapphire/search/FulltextSearchable.php
的源代码
您可以在 mysite/_config.php 中添加:
FulltextSearchable::enable(array());
这应该删除默认搜索的类,即 SiteTree(所有页面)和文件
然后可以在mysite/_config.php中添加对象扩展:
Object::add_extension('NewsPage', "FulltextSearchable('Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords')");
以下是 FulltextSearchable.php 文件中的 cmets
/**
* Enable the default configuration of MySQL full-text searching on the given data classes.
* It can be used to limit the searched classes, but not to add your own classes.
* For this purpose, please use {@link Object::add_extension()} directly:
* <code>
* Object::add_extension('MyObject', "FulltextSearchable('MySearchableField,'MyOtherField')");
* </code>
*
* Caution: This is a wrapper method that should only be used in _config.php,
* and only be called once in your code.
*
* @param Array $searchableClasses The extension will be applied to all DataObject subclasses
* listed here. Default: {@link SiteTree} and {@link File}.
*/