firebrandhq/searchable-dataobjects
Composer 安装命令:
composer require firebrandhq/searchable-dataobjects
包简介
Fork of zirak/searchable-dataobjects to include dataobjects' parent pages in search results.
README 文档
README
Firebrand Searchable DataObjects is a fork of Zirak's Searchable DataObjects.
Firebrand's version will return Pages matching a search criteria or having related Data Objects matching the search criteria. Zirak's version returns the DataObjects individual data objects.
Introduction
Complexe SilverStripe pages will sometimes need to be divided up in various parts using DataObjects. Out of the box SilverStripe will only index the content in the main WYSIWYG area of a page. This means that related DataObjects will not be indexed and that their parent pages will not be returned in search results.
Requirements
- SilverStripe 3.1
- zirak/htmlpurifier
Installation
Install the module through composer:
composer require firebrandhq/searchable-dataobjects
Make the DataObject (or Pages) implement Searchable or SearchableLinkable interface. You need to define getSearchFilter(), getTitleFields(), getContentFields(), getOwner(), IncludeInSearch()). Classes that implement the SearchableLinkable interface, must additionnaly define a Link() function.
DataObjects that are accessible via a URL should implement SearchableLinkable while DataObjects that belong to a parent object without being reable directly URL accessible should implement Searchable.
class DoNews extends DataObject implements SearchableLinkable { private static $db = array( 'Title' => 'Varchar', 'Subtitle' => 'Varchar', 'News' => 'HTMLText', 'Date' => 'Date', ); private static $has_one = array( 'Page' => 'PghNews' ); private static $has_many = array( 'Asides' => 'Aside' ); /** * Filter array * eg. array('Disabled' => 0); * @return array */ public static function getSearchFilter() { return array(); } /** * Fields that compose the Title * eg. array('Title', 'Subtitle'); * @return array */ public function getTitleFields() { return array('Title'); } /** * Fields that compose the Content * eg. array('Teaser', 'Content'); * @return array */ public function getContentFields() { return array('Subtitle', 'Content'); } /** * Parent objects that should be displayed in search results. * @return SiteTree or SearchableLinkable */ public function getOwner() { return $this; } /** * Whatever this specific Searchable should be included in search results. * This allows you to exclude some DataObjects from search results. * It plays more or less the same role that ShowInSearch plays for SiteTree. * @return boolean */ public function IncludeInSearch() { return true; } /** * Link to access this DO * @return string */ public function Link() { $this->Page->Link('news/' . $this->ID); } }
class Aside extends DataObject implements Searchable { private static $db = array( 'Header' => 'Varchar', 'Content' => 'HTMLText', ); private static $has_one = array( 'DoNews' => 'DoNews' ); /** * Filter array * eg. array('Disabled' => 0); * @return array */ public static function getSearchFilter() { return array(); } /** * Fields that compose the Title * eg. array('Title', 'Subtitle'); * @return array */ public function getTitleFields() { return array('Header'); } /** * Fields that compose the Content * eg. array('Teaser', 'Content'); * @return array */ public function getContentFields() { return array('Content'); } /** * Parent objects that should be displayed in search results. * @return SiteTree or SearchableLinkable */ public function getOwner() { return $this->DoNews; } /** * Whatever this specific Searchable should be included in search results. * This allows you to exclude some DataObjects from search results. * It plays more or less the same role that ShowInSearch plays for SiteTree. * @return boolean */ public function IncludeInSearch() { return true; } }
Extend Page and the desired DataObjects through the following yaml:
Page: extensions: - SearchableDataObject DoNews: extensions: - SearchableDataObject
Run a dev/build and then populate the search table running PopulateSearch task:
sake dev/build "flush=all"
sake dev/tasks/PopulateSearch
When you save your pages or you DataObject, they will automatically update their entry in the search table.
Note
Searchable DataObjects module use Mysql NATURAL LANGUAGE MODE search method, so during your tests be sure not to have all DataObjetcs with the same content, since words that are present in 50% or more of the rows are considered common and do not match.
From MySQL manual entry [http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html]:
A natural language search interprets the search string as a phrase in natural human language (a phrase in free text). There are no special operators. The stopword list applies. In addition, words that are present in 50% or more of the rows are considered common and do not match. Full-text searches are natural language searches if the IN NATURAL LANGUAGE MODE modifier is given or if no modifier is given.
firebrandhq/searchable-dataobjects 适用场景与选型建议
firebrandhq/searchable-dataobjects 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.04k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2015 年 06 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「search」 「silverstripe」 「dataobject」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 firebrandhq/searchable-dataobjects 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 firebrandhq/searchable-dataobjects 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 firebrandhq/searchable-dataobjects 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package to retrieve data from Google Search Console
Pimcore 6.x Relation-Fields for DataObjects and Documents
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
DataExtension that easily allows a DataObject to be viewed like a Page
Silverstripe Translatable extension for DataObjects
Abstraction Layer to index and search entities
统计信息
- 总下载量: 3.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2015-06-03