承接 fromholdio/silverstripe-fulltext-filters 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

fromholdio/silverstripe-fulltext-filters

Composer 安装命令:

composer require fromholdio/silverstripe-fulltext-filters

包简介

This module adds three fulltext SearchFilters to your SilverStripe project.

README 文档

README

This module adds three fulltext SearchFilters to your SilverStripe project.

  • FulltextBoolean - similar to the existing Fulltext filter, but uses IN BOOLEAN MODE, and transforms the search phrase to take full advantage of this. See characteristics of Boolean full-text searches here.
  • FulltextRelevance - adds relevance to the select query, accepts a 'Weight' argument which is applied to the relevance score, and provides hooks to sort results by the sum of all weighted indexes within the query
  • FulltextBooleanRelevance - same as FulltextRelevance but uses the FulltextBoolean filter as its base and basis for matching. Uses the Boolean mode relevance calculation (which can differ from Fulltext in Natural Language Mode)

N.b. - Full-text relevance scores are binary (1 or 0) in Boolean Mode, unless the table engine is InnoDB. By default SilverStripe enforces MyISAM for tables containing a fulltext index. Use fromholdio-silverstripe-fulltext-innodb to overcome this.

Requirements

Recommended

Installation

composer require fromholdio/silverstripe-fulltext-filters

Details & Usage

In short, use this like any other set of SearchFilters:

// Define your fulltext indexes:
private static $indexes = [
    'TitleFields' => [
        'type' => DBIndexable::TYPE_FULLTEXT,
        'columns' => [
            'Title',
            'MenuTitle'
        ]
    ],
    'ContentFields' => [
        'type' => DBIndexable::TYPE_FULLTEXT,
        'columns' => [
            'Content',
            'MetaDescription'
        ]
    ]
];

// Use in ORM filters:

// We're using BOOLEAN MODE matching
// Matches to the TitleFields index are weighted as five times more significant than ContentFields matches
// We're calculating the sum of relevance scores per matched record, and ordering the results by descending relevance score

public function getResults($value)
{
    $objects = ObjectClass::get()
        ->filterAny([
            'TitleFields:FulltextBooleanRelevance(5)' => $value,
            'ContentFields:FulltextBooleanRelevance' => $value
        ])
        ->sort('@TitleFieldsScore + @ContentFieldsScore DESC');
}

More documentation to come. Look at the source code in the meantime, or submit an issue.

Two key hooks:

  • You can access the relevance value the database assigns per index and per record using ->{IndexName}Relevance
  • Per the example above, these relevance values are made available within the query for sort but also available for additional where/etc, using variable names @{IndexName}Score

To Do

  • Documentation 😅

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-04-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固