SuggestParamsBuilder.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Util;
  21. use OpenSearch\Generated\Search\SearchParams;
  22. use OpenSearch\Generated\Search\Config;
  23. use OpenSearch\Generated\Search\Suggest;
  24. /**
  25. * @deprecated 随着SuggestClient的废弃而失去了历史作用
  26. */
  27. class SuggestParamsBuilder {
  28. public function __construct() {}
  29. /**
  30. * 创建一个下拉提示的搜索请求。
  31. *
  32. * @param string $appName 指定应用的名称。
  33. * @param string $suggestName 指定下拉提示的名称。
  34. * @param string $query 指定要搜索的关键词。
  35. * @param int $hits 指定要返回的词条个数。
  36. *
  37. * @return \OpenSearch\Generated\Search\SearchParams
  38. */
  39. public static function build($appName, $suggestName, $query, $hits) {
  40. $config = new Config(array('hits' => (int) $hits, 'appNames' => array($appName)));
  41. $suggest = new Suggest(array('suggestName' => $suggestName));
  42. return new SearchParams(array("config" => $config, 'query' => $query, 'suggest' => $suggest));
  43. }
  44. /**
  45. * 根据SearchParams生成下拉提示搜索的参数。
  46. *
  47. * @param \OpenSearch\Generated\Search\SearchParams $searchParams searchParams
  48. *
  49. * @return array
  50. */
  51. public static function getQueryParams($searchParams) {
  52. $query = $searchParams->query;
  53. $hits = $searchParams->config->hits;
  54. return array('query' => $query, 'hit' => $hits);
  55. }
  56. }