SuggestionClient.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Suggestion\SuggestionServiceIf;
  22. use OpenSearch\Generated\Suggestion\SuggestParams;
  23. use OpenSearch\Util\SuggestUrlParamsBuilder;
  24. use OpenSearch\Client\OpenSearchClient;
  25. /**
  26. * 应用下拉提示操作类。
  27. *
  28. * 通过制定关键词、过滤条件搜索应用的下拉提示的结果。
  29. *
  30. */
  31. class SuggestionClient implements SuggestionServiceIf
  32. {
  33. const SUGGESTION_API_PATH = "/suggestions/%s/actions/search";
  34. private $suggestionName;
  35. private $openSearchClient;
  36. /**
  37. * 构造方法。
  38. *
  39. * @param string $suggestionName 下拉提示名称
  40. * @param \OpenSearch\Client\OpenSearchClient $openSearchClient 基础类,负责计算签名,和服务端进行交互和返回结果。
  41. * @return void
  42. */
  43. public function __construct(string $suggestionName,
  44. OpenSearchClient $openSearchClient)
  45. {
  46. $this->suggestionName = $suggestionName;
  47. $this->openSearchClient = $openSearchClient;
  48. }
  49. /**
  50. * 执行搜索操作。
  51. *
  52. * @param \OpenSearch\Generated\Suggestion\SuggestParams $suggestParams 指定的查询条件
  53. * @return \OpenSearch\Generated\Common\OpenSearchResult OpenSearchResult类
  54. */
  55. public function execute(SuggestParams $suggestParams)
  56. {
  57. $path = $this->getPath();
  58. $builder = new SuggestUrlParamsBuilder($suggestParams);
  59. return $this->openSearchClient->get($path, $builder->getHttpParams());
  60. }
  61. private function getPath()
  62. {
  63. return sprintf(self::SUGGESTION_API_PATH, $this->suggestionName);
  64. }
  65. /**
  66. * @deprecated
  67. */
  68. public function search()
  69. {
  70. throw new \BadMethodCallException();
  71. }
  72. }