AppClient.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. namespace OpenSearch\Client;
  21. use OpenSearch\Generated\App\AppServiceIf;
  22. use OpenSearch\Generated\Common\Pageable;
  23. /**
  24. * 应用基本信息管理类。
  25. *
  26. * 管理应用的基本信息,包含创建应用(save)、修改应用(updateById)、删除应用(removeById)
  27. * 、获取应用的基本详情(getById)、获取应用列表(listAll)、给应用导入全量数据(reindexById)
  28. * 等方法。
  29. *
  30. */
  31. class AppClient implements AppServiceIf {
  32. private $openSearchClient = null;
  33. private $path = "/apps";
  34. /**
  35. * 构造方法。
  36. *
  37. * @param \OpenSearch\Client\OpenSearchClient $openSearchClient 基础类,负责计算签名,和服务端进行交互和返回结果。
  38. * @return void
  39. */
  40. public function __construct($openSearchClient) {
  41. $this->openSearchClient = $openSearchClient;
  42. }
  43. /**
  44. * 创建一个新应用,或者创建一个新版本。
  45. *
  46. * 创建一个新的应用或者创建一个新的版本,如果在$app中指定了name,则会创建一个新版本,否则会创建一个新应用。
  47. *
  48. * > 创建版本的个数依赖服务端的限制。
  49. *
  50. * @param string $app 要创建的应用主体JSON,包含name、type、schema、quota、first_ranks、second_ranks、summary、data_sources、suggest、fetch_fields、query_processors等信息。
  51. * @return \OpenSearch\Generated\Common\OpenSearchResult OpenSearchResult类
  52. */
  53. public function save($app) {
  54. return $this->openSearchClient->post($this->path, $app);
  55. }
  56. /**
  57. * 通过应用名称或者应用ID获取一个应用的详情信息。
  58. *
  59. * @param string $identity 要查询的应用名称或者应用ID,如果应用有多个版本,则指定应用名称为当前应用的在线版本。
  60. * @return \OpenSearch\Generated\Common\OpenSearchResult
  61. */
  62. public function getById($identity) {
  63. $path = $this->path . "/" . $identity;
  64. return $this->openSearchClient->get($path);
  65. }
  66. /**
  67. * 获取应用列表。
  68. *
  69. * @param \OpenSearch\Generated\Common\Pageable $pageable 分页信息,包含页码和每页展示条数。
  70. * @return \OpenSearch\Generated\Common\OpenSearchResult
  71. */
  72. public function listAll(Pageable $pageable) {
  73. return $this->openSearchClient->get(
  74. $this->path, array('page' => $pageable->page, 'size' => $pageable->size)
  75. );
  76. }
  77. /**
  78. * 根据指定的应用id或名称删除应用版本或者应用;当指定的为应用名称,则表示指定的为当前应用分组中的在线的应用。。
  79. *
  80. * 如果当前应用只有一个版本,则会删除这个应用的整个分组;
  81. * 如果当前应用分组有多个应用,则需要当前要删除的版本不能处于在线状态。
  82. *
  83. * @param string $identity 指定的应用ID或者应用名称。
  84. * @return \OpenSearch\Generated\Common\OpenSearchResult
  85. */
  86. public function removeById($identity) {
  87. $path = $this->path . "/" . $identity;
  88. return $this->openSearchClient->delete($path);
  89. }
  90. /**
  91. * 更新某个应用的信息。
  92. *
  93. * @param string $identity 指定的应用ID或者应用名称;当指定的为应用名称,则表示指定的为当前应用分组中的在线的应用。
  94. * @param string $app 修改一个应用的应用结构json,包含name、type、schema、quota、first_ranks、second_ranks、summary、data_sources、suggest、fetch_fields、query_processors等信息。
  95. * @return \OpenSearch\Generated\Common\OpenSearchResult
  96. */
  97. public function updateById($identity, $app) {
  98. $path = $this->path . "/" . $identity;
  99. return $this->openSearchClient->patch($path, $app);
  100. }
  101. /**
  102. * 在创建过程中全量导入数据。
  103. *
  104. * @param string $identity 指定的应用ID或者应用名称;当指定的为应用名称,则表示指定的为当前应用分组中的在线的应用。。
  105. * @return \OpenSearch\Generated\Common\OpenSearchResult
  106. */
  107. public function reindexById($identity) {
  108. $path = $this->path . "/{$identity}/actions/reindex";
  109. return $this->openSearchClient->post($path);
  110. }
  111. }