【问题标题】:Silverstripe Filter Search银条过滤器搜索
【发布时间】:2012-11-30 17:16:51
【问题描述】:

我的 silverstripe 网站中有一个新闻部分,我想使用 Silverstripe 的 FulltextSeach 功能:

FulltextSearchable::enable();

到目前为止效果很好。但我希望我的结果中只有 NewsPages。有没有办法过滤搜索,以便您仅获得 certin pageType 作为结果?

提前致谢, 克里斯

【问题讨论】:

    标签: full-text-search silverstripe


    【解决方案1】:

    这是未经测试的代码,但我刚刚查看了 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}.
     */
    

    【讨论】:

      猜你喜欢
      • 2018-06-22
      • 1970-01-01
      • 2019-09-19
      • 2011-12-22
      • 2011-08-14
      • 2019-03-04
      • 2018-09-24
      • 2018-12-18
      • 2012-03-20
      相关资源
      最近更新 更多