Full text search Silverstripe筛选器搜索
我的silverstripe站点中有一个新闻部分,我想使用silverstripe的FullTextSearch功能:Full text search Silverstripe筛选器搜索,full-text-search,silverstripe,Full Text Search,Silverstripe,我的silverstripe站点中有一个新闻部分,我想使用silverstripe的FullTextSearch功能: FulltextSearchable::enable(); 到目前为止效果不错。但我只希望结果中有新闻页面。例如,有没有一种方法可以过滤搜索,使您只获得certin pageType作为结果 提前感谢,, Chris这是未经测试的代码,但我刚刚查看了sapphire/search/FulltextSearchable.php的源代码 在mysite/_config.php中,
FulltextSearchable::enable();
到目前为止效果不错。但我只希望结果中有新闻页面。例如,有没有一种方法可以过滤搜索,使您只获得certin pageType作为结果
提前感谢,,
Chris这是未经测试的代码,但我刚刚查看了sapphire/search/FulltextSearchable.php的源代码 在mysite/_config.php中,您可以添加:
FulltextSearchable::enable(array());
这将删除默认的搜索类,即SiteTree(所有页面)和File
然后可以在mysite/_config.php中添加对象扩展:
Object::add_extension('NewsPage', "FulltextSearchable('Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords')");
下面是FulltextSearchable.php文件中的注释
/**
* 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}.
*/