定制 dnadesign/silverstripe-elemental-textcontentforsearch 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dnadesign/silverstripe-elemental-textcontentforsearch

Composer 安装命令:

composer require dnadesign/silverstripe-elemental-textcontentforsearch

包简介

A set of helper methods to facilitate indexing elemental pages text content

README 文档

README

A set of helper methods to facilitate searching elemental pages

Requirements

  • Silverstripe CMS ^6
  • Silverstripe Elemental ^6

Installation

composer require dnadesign/silverstripe-elemental-textcontentforsearch

The following YAML config will enable elements on every Page object, replacing the standard Content rich text field and add access to the getTextContentForSearch method

mysite/_config/elements.yml

Page:
  extensions:
    - DNADesign\Elemental\Extensions\ElementalPageExtension
    - DNADesign\Elemental\Extensions\ElementalPageTextSearchExtension

Usage

SolrIndex

We recommend you use the TextContentForSearch instead of the ElementForSearch method in your index. This avoids rendering the entire elemental area, which would include images and complex elements, which consumes a lot of resources during render and don't end up in the index anyway.

class ElementalSolrIndex extends SolrIndex
{
    public function init()
    {
        $this->addClass(Page::class);
        $this->addAllFulltextFields();
        /** @see ElementalPageTextContentSearchExtension::getTextContentForSearch */
        $this->addFulltextField('TextContentForSearch');
    }
}

Configuration

By default, the process will extract any Varchar, Text and HTMLText field from the elements. If you require any other type of fields to be considered for indexing, you ca update the config as follow:

Page:
  db_text_field_types:
    - CustomFieldType

You can exclude fields per element. By default, the Style and ExtraClass fields are excluded as they wouldn't bring any value to the search. To exclude a field, you can either set the config on the class or in the yaml:

DNADesign\Elemental\Models\ElementContent:
  exclude_fields_from_search:
    - Title

or

class MyCustomElement extends BaseElement
{
    private static $exclude_fields_from_search = [
        'Title'
    ];
}

In reverse, you can add a field in the same way.

DNADesign\Elemental\Models\ElementContent:
  include_fields_in_search:
    - AlternativeText

or

class MyCustomElement extends BaseElement
{
    private static $include_fields_in_search = [
        'AlternativeText'
    ];
}

In addition, you can implement a updateTextFieldsForSearch method on any element or extension to update the list of fields to include in search.

Some elements may have complex relationships that are not explored by the default process. You can implement addTextContentForSearch to concatenate extra content to the final string.

class MyCustomElement extends BaseElement
{
    private static $has_many = [
        'AccordionItems' => AccordionItem::class
    ];

    public function addTextContentForSearch()
    {
        $titles = [];
        foreach($this->AccordionItems() as $item) {
            $titles[] = $item->Title;
        }
        return implode(' ', $titles);
    }
}

Ultimately, you can manipulate the final string to be return by implementing updateTextContentForSearch method.

class MyCustomElement extends BaseElement
{
    public function updateTextContentForSearch($string)
    {
        // Remove any occurrence of forbiddenWord in the final string
        return = str_replace('forbiddenWord', '', $string);
    }
}

By default, every element is considered for indexing. If you wish to exclude an element from the search, you can use the config as follow:

DNADesign\Elemental\Models\ElementContent:
  exclude_content_from_search: true

or

class MyCustomElement extends BaseElement
{
    private static $exclude_content_from_search = true;
}

Debugging

As it is difficult to see what is being included in the solr index, the module exposes a read only text field with the content generated by the getTextContentForSearch method. You can hide this field by amending the config:

DNADesign\Elemental\Extensions\ElementalPageTextSearchExtension:
  show_text_content_search_in_cms: false

Notes:

  • The introspective process will explore any VirtualElement and extract the parent element text fields

To do:

  • Add an option to store the search string in the DB on save?

dnadesign/silverstripe-elemental-textcontentforsearch 适用场景与选型建议

dnadesign/silverstripe-elemental-textcontentforsearch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.47k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「silverstripe」 「elemental」 「fulltextsearch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dnadesign/silverstripe-elemental-textcontentforsearch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dnadesign/silverstripe-elemental-textcontentforsearch 我们能提供哪些服务?
定制开发 / 二次开发

基于 dnadesign/silverstripe-elemental-textcontentforsearch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2022-09-20