reliefweb/api-indexer

本包的最新版本(v2.8.0)没有提供许可证信息。

独立库,用于将RW数据库索引到API的elasticsearch索引中。


README

独立应用,用于将RW数据库内容索引到API的elasticsearch索引中,无需Drupal。

命令行

Usage: php PATH/TO/Indexer.php [options] <entity-bundle>
    -h, --help display this help
    -e, --elasticsearch <arg> Elasticsearch URL, defaults to http://127.0.0.1:9200
    -H, --mysql-host <arg> Mysql host, defaults to localhost
    -P, --mysql-port <arg> Mysql port, defaults to 3306
    -u, --mysql-user <arg> Mysql user, defaults to root
    -p, --mysql-pass <arg> Mysql pass, defaults to none
    -d, --database <arg> Database name, deaults to reliefwebint_0
    -b, --base-index-name <arg> Base index name, deaults to reliefwebint_0
    -t, --tag <arg> Tag appended to the index name, defaults to empty string
    -w, --website <arg> Website URL, deaults to https://reliefweb.int
    -l, --limit <arg> Maximum number of entities to index, defaults to 0 (all)
    -o, --offset <arg> ID of the entity from which to start the indexing, defaults to the most recent one
    -f, --filter <arg> Filter documents to index. Format: 'field1:value1,value2+field2:value1,value2'
    -c, --chunk-size <arg> Number of entities to index at one time, defaults to 500
    -i, --id Id of an entity item to index, defaults to 0 (none)
    -r, --remove Removes an entity if 'id' is provided or the index for the given entity bundle
    -a, --alias Set up the alias for the index after the indexing, ignored if id is provided
    -A, --alias-only Set up the alias for the index without indexing, ignored if id is provided

使用composer添加库

composer require "reliefweb/api-indexer"

然后创建一个新的Manager,提供一个选项数组(参见上面对全名选项的使用)

use RWAPIIndexer\Manager;

// Indexing options to index all reports.
$options = array(
  'bundle' => 'report',
  'elasticsearch' => 'http://127.0.0.1:9200',
  'mysql-host' => 'localhost',
  'mysql-port' => 3306,
  'mysql-user' => 'root',
  'mysql-pass' => '',
  'database' => 'DATABASE_NAME',
  'base-index-name' => 'ELASTICSEARCH_INDEX_PREFIX',
  'tag' => '',
  'website' => 'https://reliefweb.int',
  'limit' => 0,
  'offset' => 0,
  'chunk-size' => 500,
  'id' => 0,
  'remove' => FALSE,
  'alias' => TRUE,
);

// Create the indexing manager.
$manager = new Manager($options);

// Index or delete based on the provided options.
$manager->execute();

Markdown

建议安装php-hoedown。如果没有安装,索引器将默认使用较慢的PHP League CommonMark库。