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
VirtualElementand 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dnadesign/silverstripe-elemental-textcontentforsearch 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block that displays featured content - large image, title, description and link.
A multi file block for SilverStripe Elemental
Flexslider slideshow content block for Silverstripe Elemental
A block to display a list of links to child pages, or pages in current level
Element displaying information in regards to answers given to questions
Quick gallery content block for Silverstripe CMS
统计信息
- 总下载量: 4.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2022-09-20