tuanlerepo/statamic-es 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tuanlerepo/statamic-es

Composer 安装命令:

composer require tuanlerepo/statamic-es

包简介

Elasticsearch driver for Statamic

README 文档

README

This addon add's a Elasticsearch driver to Statamics builtin search system ( docs ).

Setup index

Indexes are configured in config/statamic/search.php and uses the standard Statamic index configuration. There's a few extra nice configuration options.

Here's an entry in indexes for the pages collection:

'public' => [
  'driver' => 'elasticsearch',
  'searchables' => 'collection:pages',
  'fields' => ['title', 'description', 'content'],
],

Here's an example entry in the drivers section defining the connection properties for your Elasticsearch server.

'elasticsearch' => [
    'hosts' => [[
       'scheme' => env('ELASTICSEARCH_SCHEME', 'http'),
       'host' => env('ELASTICSEARCH_HOST', '127.0.0.1'),
       'port' => env('ELASTICSEARCH_PORT', 9200),
    ]]
],

Content transformation

Statamic supports transformers for the index data, but the current implementation is not compatible with how Laravel serializes the configuration when running php artisan optimize. Therefore this driver has it's own system that can be configured like this:

'public' => [
  ...
  'transforms' => ['content' => 'bardToText'],
],

Available transformers

  • 'bardToText`, converts the ProseMirror data structure into plain text so it can be indexed.
  • 'handle', converts fields that has a handle (eg. site and collection) into the handle text.

Analyzers

Elasticsearch supports different text analyzers for indexing. The analyzer determines how tokenization, stop-words and stemming is handled. You can set the default analyzer used (for all fields) like this:

'public' => [
  'driver' => 'elasticsearch',
  'searchables' => 'collection:pages',
  'fields' => ['title', 'description', 'content'],
  'analyzer' => 'danish'
],

If not set, the standard analyzer is used. See list of available language analyzers here.

Field boost

You can boost individual fields by defining a boost value.

'boost' => [
    'title' => '2',
    'keywords' => '2'
]

Updating indexes

Whenever you save an item in the Control Panel it will automatically update any appropriate indexes as this is extending the Statamic search. As expected you can update the index via command line.

php please search:update public

Verify indexed data

You can verify that your elaticsearch index looks correct with:

curl 127.0.0.1:9200/_cat/indices/public?v

Or make queries directly with:

curl 127.0.0.1:9200/public/_search?q=test | jq

Templating

You can use the default Statamic search tag like usual:

{{ search:results index="public"}}
    {{ if no_results }}
        <h2>No results.</h2>
    {{ else }}
        <a href="{{ url }}">
            <div>{{ title }}</div>
            <p>{{ description | truncate:180 }}</p>
        </a>
    {{ /if }}
{{ /search:results }}

Livewire componenent with pagination

The included Livewire component supports pagination using Elasticsearch for the pagination. This requires that the fields status are indexed so add them to the config:

'public' => [
  ....
  'fields' => [ ... 'status'],
],

If you have multiple sites and wan't the search page to only return results from a specific site then you must add the site field to the index. The site field is an object so it must be transformed with the handle transformer.

'public' => [
  ....
  'fields' => [ ... 'status', 'site'],
  'transforms' => ['site' => 'handle'],
],     

Then you need to have Livewire support for your antlers templates. The easy way is to install Jonas's addon :

composer require jonassiewertsen/statamic-livewire

Then make your search antlers template including:

{{ livewire:styles }}
{{ livewire:elasticsearch.search index="public" size="10"}}
{{ livewire:scripts }}  

The template can be overridden by publishing it:

php artisan vendor:publish --tag=elasticsearch-views

Planned features

  • Set analyzer based om documents site locale
  • Configurable multi-match query type

tuanlerepo/statamic-es 适用场景与选型建议

tuanlerepo/statamic-es 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.52k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 tuanlerepo/statamic-es 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2024-12-11