定制 fahlgrendigital/packages-statamic-algolia-support 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

fahlgrendigital/packages-statamic-algolia-support

Composer 安装命令:

composer require fahlgrendigital/packages-statamic-algolia-support

包简介

Support for the Algolia driver in Statamic applications.

README 文档

README

Add helpful support classes for working with the Algolia driver in Statamic applications.

Compatibility: Statamic 5.x and 6.x | Laravel 11.x and 12.x | PHP 8.3+

Installation

$ composer require fahlgrendigital/packages-statamic-algolia-support

Publish config

$ php artisan vendor:publish --tag=statamic-algolia-support-config

Usage

This package focuses on three areas of support for the Algolia driver in Statamic applications:

Transformers

Transformers are Statamic search transformers that convert complex Statamic field types into Algolia-compatible formats. Register them in your config/statamic/search.php under a field's transformer key.

CollectionTransformer

Extracts the handle string from a collection object. Useful for configuring Algolia facets that filter by collection.

use Fahlgrendigital\PackagesStatamicAlgoliaSupport\Search\Transformers\CollectionTransformer;

// In config/statamic/search.php
'fields' => [
    'collection' => ['transformer' => CollectionTransformer::class],
],

Returns: string|null — the collection handle, or null if empty.

DateTransformer

Converts a Carbon date object into a formatted date string (Y-m-d H:i:s). Compatible with Carbon 2.x and 3.x (Statamic 6).

use Fahlgrendigital\PackagesStatamicAlgoliaSupport\Search\Transformers\DateTransformer;

'fields' => [
    'date' => ['transformer' => DateTransformer::class],
],

Returns: string|null — formatted date string, or passes through non-Carbon values unchanged.

Statamic 6 note: Statamic 6 requires Carbon 3. Dates now convert to UTC at runtime. If your app uses a non-UTC timezone, configure 'localize_dates_in_modifiers' => true in config/statamic/system.php.

MarkupTransformer

Strips HTML from Bard and Textarea fields, returning plain searchable text. For Bard fields, it uses Statamic's bardText modifier to properly handle the ProseMirror document structure.

use Fahlgrendigital\PackagesStatamicAlgoliaSupport\Search\Transformers\MarkupTransformer;

'fields' => [
    'content' => ['transformer' => MarkupTransformer::class], // Bard or Textarea
],

Returns: string|null — plain text content, or null if empty.

TaxonomyTransformer

Resolves taxonomy term references (slugs stored on an entry) into structured arrays containing id, slug, and title. Results are cached for 1 hour per term to avoid repeated lookups during large index builds.

Works with both flat-file entries and Eloquent entries.

use Fahlgrendigital\PackagesStatamicAlgoliaSupport\Search\Transformers\TaxonomyTransformer;

'fields' => [
    'tags' => ['transformer' => TaxonomyTransformer::class],
],

Returns: array|null['tags' => [['id' => ..., 'slug' => ..., 'title' => ...], ...]], or null for non-entry searchables, or [] for entries with no terms.

RecordUrlTransformer

Generates the URL for an Entry or Asset searchable. Returns null for other searchable types (e.g. taxonomy terms).

use Fahlgrendigital\PackagesStatamicAlgoliaSupport\Search\Transformers\RecordUrlTransformer;

'fields' => [
    'url' => ['transformer' => RecordUrlTransformer::class],
],

Returns: string|null — the URL for entries and assets, null otherwise.

Indexes

The index builder exports Statamic search indexes to JSON or CSV files on a configured filesystem disk. This is useful for:

  • Bulk-replacing an Algolia index without hitting record-level API limits
  • Keeping index snapshots across environments
  • Feeding downstream services via the Index API

Filesystem disk configuration

Define a disk in config/filesystems.php:

'algolia-indexes' => [
    'driver' => 'local',
    'root'   => storage_path('app/algolia-indexes'),
],

Then set ALGOLIA_SUPPORT_DISK=algolia-indexes in your .env (or publish and edit config/algolia-support.php).

Commands

Build a single index export:

php artisan algolia:search-index:build-file {index} -T json/csv [-D] [--json-stats]
Option Description
{index} The Statamic search index key (must exist in config/statamic/search.php)
-T, --file-type Export format: json or csv
-D, --dry-run Run without writing any files
--json-stats Print min/max/avg record sizes after building (JSON only)

Files are named search-index-{index}-{timestamp}.{ext}. Only the 3 most recent files per index are kept; older files are deleted automatically.

Build computed (combined) indexes:

php artisan algolia:build-computed-indexes

Merges records from multiple Algolia indexes (fetched via the Algolia API) into a single JSON file. Configure sources in config/algolia-support.php:

'computed_indexes' => [
    'combined_products' => [
        'sources' => ['products_en', 'products_es'],
    ],
],

Note: AlgoliaBuildComputedIndexes uses the Algolia PHP client v3 API. Upgrading to client v4 will require rewriting this command for the new API surface.

Index API

The package registers a read-only API endpoint that serves the most recently built index file:

GET /api/algolia/indexes/{index}

Returns the latest search-index-{index}-*.json file from the configured disk as a binary file response. Returns 404 if the index doesn't exist or no file has been built yet.

The URI path is configurable via ALGOLIA_SUPPORT_API_URI (default: /algolia/indexes).

Configuration reference

// config/algolia-support.php
return [
    // Filesystem disk name where index exports are stored
    'disk'             => env('ALGOLIA_SUPPORT_DISK', 'algolia-indexes'),

    // URI prefix for the index retrieval API
    'api_uri'          => env('ALGOLIA_SUPPORT_API_URI', '/algolia/indexes'),

    // PHP memory limit for the index builder command
    'memory_limit'     => '2028M',

    // Computed indexes: each key is the output index name,
    // 'sources' lists Algolia index names to merge from
    'computed_indexes' => [],
];

Statamic 5 → 6 upgrade notes

Area Impact Action
statamic/cms constraint Package now supports ^5.0|^6.0. Run composer update.
Carbon 3 Low DateTransformer uses ->format() which is compatible with Carbon 3. Review UTC timezone behavior (see note above).
Search searchables: all removed Medium Removed in Statamic 6. Replace with 'content' or an explicit list in your config/statamic/search.php.
Algolia PHP client v3 Pending AlgoliaBuildComputedIndexes uses v3-specific APIs. Monitor whether Statamic 6 or its Algolia driver requires client v4 and update accordingly.
Entry status queries None This package does not use ->where('status', ...). No action needed.
Vue 3 / Control Panel None This package has no Control Panel components.

fahlgrendigital/packages-statamic-algolia-support 适用场景与选型建议

fahlgrendigital/packages-statamic-algolia-support 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 285 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cms」 「laravel」 「flat file」 「statamic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fahlgrendigital/packages-statamic-algolia-support 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fahlgrendigital/packages-statamic-algolia-support 我们能提供哪些服务?
定制开发 / 二次开发

基于 fahlgrendigital/packages-statamic-algolia-support 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 285
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-30