locomotivemtl/charcoal-contrib-search

0.3.2.3 2024-06-10 16:04 UTC

This package is auto-updated.

Last update: 2024-09-10 16:41:52 UTC


README

License Latest Stable Version

A Charcoal service provider with my cool feature.

目录

安装

首选(也是唯一支持)的方法是使用 Composer

$ composer require locomotivemtl/charcoal-contrib-search

依赖项

必需

配置

在你的项目配置文件中,需要引入搜索模块

{
    "modules": {
        "charcoal/search/search": {}
    }
}

用法

该模块使用 GET 添加了一个 search 路由操作。你可以通过 http://project-url.com/search?keyword=[keyword] 访问。除非你运行 IndexContent 脚本,否则不会得到任何结果。

在运行脚本之前,你需要设置

// Once a day at midnight
// You need to precise the base URL as it won'T be provided by the cli
0 0 * * * cd /[project]/web && /usr/local/bin/php /[project]/web/vendor/bin/charcoal admin/search/index-content -u http://project-url.com/

要索引的每个 sitemap 对象必须包含 data.iddata.objType 才能被索引

{
    "sitemap": {
        "xml": {
            "l10n": true,
            "check_active_routes": true,
            "relative_urls": false,
            "objects": {}
        },
        "searchables": {
            "l10n": true,
            "check_active_routes": true,
            "relative_urls": false,
            "transformer": "charcoal/search/transformer/indexable",
            "objects": {
                "app/object/section": {
                    "filters": {},
                    "data": {
                        "id": "{{id}}",
                        "objType": "{{objType}}"
                    }
                },
                
            }
        }
    }
}

参数

  • -u (--url) 网站URL。由于这是在 cron 脚本中运行的,因此是必需的。
  • -c (--config) Sitemap 构建器键(默认为 xml)。
  • -n (--no_index_class) 过滤掉爬取页面内容的类。默认为 php-no_index
  • -i (--index_element_id) 要索引的爬取页面的元素 ID。默认为整个页面主体。

开发

API 文档

开发依赖项

  • [php-coveralls/php-coveralls][phpcov]
  • [phpunit/phpunit][phpunit]
  • [squizlabs/php_codesniffer][phpcs]

编码风格

charcoal-contrib-search 模块遵循 Charcoal 编码风格

可以使用 composer phpcs 执行编码风格验证/强制执行。还有一个自动修复器,可以使用 composer phpcbf

致谢

许可

Charcoal 根据 MIT 许可证授权。有关详细信息,请参阅 LICENSE