定制 fork/craft-elastica 二次开发

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

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

fork/craft-elastica

Composer 安装命令:

composer require fork/craft-elastica

包简介

A plugin to connect to Elasticsearch and persist elements via hooks

README 文档

README

Fork Logo

Elastica Plugin for Craft 5.x

Table of contents

Features

  • Index entries and other elements in Elasticsearch
  • Customize Index data structures via hooks
  • Define Index Templates to configure the Index and its fields and mapping in Elasticsearch
  • Re-Index contents via utility or console command

Requirements

  • Craft CMS >= 5.x

Version Matrix

Elastica Version Craft Version ElasticSearch Version Hint
5.x 5.x 8.x Uses new index template format
4.x 5.x 8.x Uses deprecated index template format
3.x 5.x 7.x
2.x 4.x 7.x

Setup

1. Install

Install the package

cd /path/to/project
composer require fork/craft-elastica

2. Configuration

Go to the plugin settings page and enter a index prefix name which is prepended to the indexes being created in Elasticsearch. The name of the index is generated from this prefix. Also provide the hostname of the elasticsearch instance.

Usage

To generate the data to index register event handlers in your own module or plugin class like this:

// initialize elasticsearch indexer
Event::on(
   Indexer::class,
   Indexer::EVENT_INDEXER_INIT,
   function (IndexerInitEvent $event) {
       $event->addSectionHandles([
           'articles',
       ]);
       $event->addCategoryGroupHandles([
           'topics',
       ]);
       $event->addVolumeHandles([
           'images',
       ]);
   }
);
// build elasticsearch index data
Event::on(
   Indexer::class,
   Indexer::EVENT_BEFORE_INDEX_DATA,
   function (IndexEvent $event) {
       // build your custom data structure to index
       $indexData = MyCustomPlugin::$plugin->mySearchService->getIndexData($event->sender);
       $event->indexData = $indexData;
   }
);

Environment based configuration

You can make the plugin's configuration environment based by adding an elastica.php file in your config directory with the following contents. This is just an example, you can name your environment variables as you want.

use craft\helpers\App;

return [
    'indexingEnabled' => App::env('ELASTICSEARCH_INDEXING_ENABLED') ?? true,
    'hosts' => [
        [
            App::env('CRAFT_ENVIRONMENT'),
            App::env('ELASTICSEARCH_URL'),
            App::env('ELASTICSEARCH_INDEX_PREFIX'),
        ]
    ]
];

Roadmap

  • Logo
  • Index categories
  • Maybe include search proxy
  • Exclude sites via settings
  • Show index info / test index in utility
  • More documentation
Made with love by Fork

Brought to you by Fork Unstable Media GmbH

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固