fromholdio/silverstripe-fulltext-filters

此模块向您的 SilverStripe 项目添加了三个全文搜索过滤器。

安装次数: 1,911

依赖关系: 0

建议者: 2

安全: 0

星星: 1

关注者: 2

分支: 1

开放问题: 1

类型:silverstripe-vendormodule

3.0.0 2023-06-21 15:53 UTC

This package is auto-updated.

Last update: 2024-09-21 18:24:43 UTC


README

此模块向您的 SilverStripe 项目添加了三个全文 SearchFilter

  • FulltextBoolean - 与现有的 Fulltext 过滤器类似,但使用 IN BOOLEAN MODE,并将搜索短语转换为充分利用这一点。 在此处查看布尔全文搜索的特点。
  • FulltextRelevance - 向选择查询添加相关性,接受一个应用于相关性得分的 'Weight' 参数,并提供钩子以按查询中所有加权索引的总和排序结果
  • FulltextBooleanRelevance - 与 FulltextRelevance 相同,但其基础和匹配基础是 FulltextBoolean 过滤器。使用布尔模式的相关性计算(可能与自然语言模式中的全文不同)

注意 - 在布尔模式下,全文相关性得分是二进制的(1或0),除非表引擎是 InnoDB。默认情况下,SilverStripe 强制使用 MyISAM 作为包含全文索引的表。使用 fromholdio-silverstripe-fulltext-innodb 来克服这一点。

要求

推荐

安装

composer require fromholdio/silverstripe-fulltext-filters

详细信息 & 使用

简而言之,就像使用任何其他一组 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');
}

更多文档即将推出。同时查看源代码,或提交问题。

两个关键钩子

  • 您可以使用 ->{IndexName}Relevance 访问数据库为每个索引和每条记录分配的相关性值
  • 根据上面的示例,这些相关性值在查询的 sort 中可用,也可以通过变量名称 @{IndexName}Score 在额外的 where/etc 中使用

待办事项

  • 文档 😅