|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Typesense; |
| 4 | + |
| 5 | +use Http\Client\Exception as HttpClientException; |
| 6 | +use Typesense\Exceptions\TypesenseClientError; |
| 7 | + |
| 8 | +/** |
| 9 | + * Class Document |
| 10 | + * |
| 11 | + * @package \Typesense |
| 12 | + * @date 4/5/20 |
| 13 | + * @author Abdullah Al-Faqeir <abdullah@devloops.net> |
| 14 | + */ |
| 15 | +class Stopwords |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var ApiCall |
| 19 | + */ |
| 20 | + private $apiCall; |
| 21 | + |
| 22 | + public const STOPWORDS_PATH = '/stopwords'; |
| 23 | + |
| 24 | + /** |
| 25 | + * Document constructor. |
| 26 | + * |
| 27 | + * @param ApiCall $apiCall |
| 28 | + */ |
| 29 | + public function __construct(ApiCall $apiCall) |
| 30 | + { |
| 31 | + $this->apiCall = $apiCall; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @return array|string |
| 36 | + * @throws HttpClientException |
| 37 | + * @throws TypesenseClientError |
| 38 | + */ |
| 39 | + public function get(string $stopwordsName) |
| 40 | + { |
| 41 | + return $this->apiCall->get( |
| 42 | + $this->endpointPath($stopwordsName), |
| 43 | + [] |
| 44 | + ); |
| 45 | + } |
| 46 | + /** |
| 47 | + * @return array|string |
| 48 | + * @throws HttpClientException |
| 49 | + * @throws TypesenseClientError |
| 50 | + */ |
| 51 | + public function getAll() |
| 52 | + { |
| 53 | + return $this->apiCall->get(static::STOPWORDS_PATH, []); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @param array $options |
| 58 | + * |
| 59 | + * @return array |
| 60 | + * @throws HttpClientException |
| 61 | + * @throws TypesenseClientError |
| 62 | + */ |
| 63 | + public function put(array $options = []) |
| 64 | + { |
| 65 | + $stopwordsName = $options['stopwords_name']; |
| 66 | + $stopwordsData = $options['stopwords_data']; |
| 67 | + return $this->apiCall->put( |
| 68 | + $this->endpointPath($stopwordsName), |
| 69 | + ['stopwords' => $stopwordsData] |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @param $presetName |
| 75 | + * @return array |
| 76 | + * @throws HttpClientException |
| 77 | + * @throws TypesenseClientError |
| 78 | + */ |
| 79 | + public function delete($presetName) |
| 80 | + { |
| 81 | + return $this->apiCall->delete( |
| 82 | + $this->endpointPath($presetName) |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @param $stopwordsName |
| 88 | + * @return string |
| 89 | + */ |
| 90 | + private function endpointPath($stopwordsName) |
| 91 | + { |
| 92 | + return sprintf( |
| 93 | + '%s/%s', |
| 94 | + static::STOPWORDS_PATH, |
| 95 | + $stopwordsName |
| 96 | + ); |
| 97 | + } |
| 98 | +} |
0 commit comments