<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Vendor\ES; use Elasticsearch\ClientBuilder; class ESBaseUtil { public static function createIndex($fnOXp, $NnUNB = 'v1') { if (!isset(static::$tableProperties[$fnOXp])) { throw new \Exception('不存在的索引'); } if (!self::client()->indices()->exists(array('index' => $fnOXp . '_' . $NnUNB))) { self::client()->indices()->create(array('index' => $fnOXp . '_' . $NnUNB, 'body' => array('settings' => array('max_result_window' => 50000), 'mappings' => array($fnOXp => array('properties' => static::$tableProperties[$fnOXp]))))); } } public static function deleteIndex($fnOXp, $NnUNB = 'v1') { if (!isset(static::$tableProperties[$fnOXp])) { throw new \Exception('不存在的索引'); } if (self::client()->indices()->exists(array('index' => $fnOXp . '_' . $NnUNB))) { self::client()->indices()->delete(array('index' => $fnOXp . '_' . $NnUNB)); } } public static function deleteAlias($fnOXp, $NnUNB = 'v1') { if (!isset(static::$tableProperties[$fnOXp])) { throw new \Exception('不存在的索引'); } if (self::client()->indices()->existsAlias(array('name' => $fnOXp))) { self::client()->indices()->deleteAlias(array('index' => $fnOXp . '_' . $NnUNB, 'name' => $fnOXp)); } } public static function putAlias($fnOXp, $NnUNB = 'v1') { if (!isset(static::$tableProperties[$fnOXp])) { throw new \Exception('不存在的索引'); } if (!self::client()->indices()->existsAlias(array('name' => $fnOXp))) { self::client()->indices()->putAlias(array('index' => $fnOXp . '_' . $NnUNB, 'name' => $fnOXp)); } } public static function stats() { return self::client()->indices()->stats(); } public static function statsIndex($vb_pv) { goto zsPMG; kJiQV: if (!empty($GUUT2['indices'])) { foreach ($GUUT2['indices'] as $l0ek5 => $vuqB0) { if (preg_match("/^{$vb_pv}_v\\d+\$/", $l0ek5)) { return $vuqB0; } } } goto L1T6K; L1T6K: return null; goto b1dKc; zsPMG: $GUUT2 = self::client()->indices()->stats(); goto kJiQV; b1dKc: } public static function client($IOfH1 = array()) { goto H2Njg; TMHS7: return $hHLym; goto E0a5_; ql9rM: if (null === $hHLym) { goto D2iJ3; D2iJ3: $DxXWh = modstart_config(); goto RBzUu; RBzUu: $Hc0Vo = array(array_merge(array('host' => $DxXWh->getWithEnv('moduleESHost'), 'port' => $DxXWh->getWithEnv('moduleESPort'), 'scheme' => 'http', 'user' => $DxXWh->getWithEnv('moduleESUser'), 'pass' => $DxXWh->getWithEnv('moduleESPass')), $IOfH1)); goto XHEI1; XHEI1: $hHLym = ClientBuilder::create()->setHosts($Hc0Vo)->build(); goto s1SvV; s1SvV: } goto TMHS7; H2Njg: static $hHLym = null; goto ql9rM; E0a5_: } public static function save($fnOXp, $Lu5WV) { goto L_x1P; g9gmN: $hHLym = static::client(); goto FLx79; FLx79: $vA6gr = self::client()->index(array('index' => $fnOXp, 'type' => $fnOXp, 'id' => $Lu5WV['id'], 'body' => $Lu5WV)); goto FixOI; L_x1P: if (!isset(static::$tableProperties[$fnOXp])) { throw new \Exception('不存在的索引'); } goto g9gmN; FixOI: } public static function saveBulk($fnOXp, $vKRZ2) { goto Cm2bI; szM5Y: foreach ($vKRZ2 as $Lu5WV) { $P5zGm[] = array('index' => array('_index' => $fnOXp, '_id' => $Lu5WV['id'], '_type' => $fnOXp)); $P5zGm[] = $Lu5WV; } goto Gomrn; Gomrn: $hHLym = static::client(); goto YZz3T; YZz3T: $vA6gr = self::client()->bulk(array('index' => $fnOXp, 'type' => $fnOXp, 'body' => $P5zGm)); goto Ht0pg; oY8fh: $P5zGm = array(); goto szM5Y; Cm2bI: if (!isset(static::$tableProperties[$fnOXp])) { throw new \Exception('不存在的索引'); } goto oY8fh; Ht0pg: } }