perf: 优化ES模块

This commit is contained in:
kuaifan
2025-03-08 11:04:43 +08:00
parent 58cb49b125
commit ed8e443f3a
3 changed files with 35 additions and 23 deletions

View File

@@ -19,7 +19,7 @@ class ElasticSearchBase
*
* @var \Elastic\Elasticsearch\Client
*/
public $client;
protected $client;
/**
* 当前操作的索引名称
@@ -279,4 +279,30 @@ class ElasticSearchBase
return ['error' => $e->getMessage(), 'hits' => ['total' => ['value' => 0], 'hits' => []]];
}
}
/**
* 索引名称
*/
const indexName = 'default';
/**
* 获取索引名称
* @param string $index 索引名称
* @param string|null $prefix 索引前缀
* @param string|null $subfix 索引后缀
* @return string
*/
public static function indexName($index = '', $prefix = '', $subfix = '')
{
$index = $index ?: static::indexName;
$prefix = $prefix ?: env('ES_INDEX_PREFIX', '');
$subfix = $subfix ?: env('ES_INDEX_SUFFIX', '');
if ($prefix) {
$index = rtrim($prefix, '_') . '_' . $index;
}
if ($subfix) {
$index = $index . '_' . ltrim($subfix, '_');
}
return $index;
}
}