|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2014-Present Couchbase, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +declare(strict_types=1); |
| 20 | + |
| 21 | +namespace Couchbase\Management; |
| 22 | + |
| 23 | +use Couchbase\Extension; |
| 24 | + |
| 25 | +class ScopeSearchIndexManager implements ScopeSearchIndexManagerInterface |
| 26 | +{ |
| 27 | + private $core; |
| 28 | + private string $bucketName; |
| 29 | + private string $scopeName; |
| 30 | + |
| 31 | + public function __construct($core, string $bucketName, string $scopeName) |
| 32 | + { |
| 33 | + $this->core = $core; |
| 34 | + $this->bucketName = $bucketName; |
| 35 | + $this->scopeName = $scopeName; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Fetches scope-level index with the specified name from the server |
| 40 | + * |
| 41 | + * @param string $indexName |
| 42 | + * @param GetSearchIndexOptions|null $options |
| 43 | + * @return SearchIndex |
| 44 | + * |
| 45 | + * @since 4.1.7 |
| 46 | + * |
| 47 | + * @VOLATILE: This API is subject to change at any time. |
| 48 | + */ |
| 49 | + public function getIndex(string $indexName, GetSearchIndexOptions $options = null): SearchIndex |
| 50 | + { |
| 51 | + $result = Extension\scopeSearchIndexGet($this->core, $this->bucketName, $this->scopeName, $indexName, GetSearchIndexOptions::export($options)); |
| 52 | + |
| 53 | + return SearchIndex::import($result); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Fetches all scope-level indexes from the server |
| 58 | + * |
| 59 | + * @param GetAllSearchIndexesOptions|null $options |
| 60 | + * @return array |
| 61 | + * |
| 62 | + * @since 4.1.7 |
| 63 | + * |
| 64 | + * @VOLATILE: This API is subject to change at any time. |
| 65 | + */ |
| 66 | + public function getAllIndexes(GetAllSearchIndexesOptions $options = null): array |
| 67 | + { |
| 68 | + $result = Extension\scopeSearchIndexGetAll($this->core, $this->bucketName, $this->scopeName, GetAllSearchIndexesOptions::export($options)); |
| 69 | + $indexes = []; |
| 70 | + foreach ($result as $index) { |
| 71 | + $indexes[] = SearchIndex::import($index); |
| 72 | + } |
| 73 | + return $indexes; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Upserts scope-level index to the server |
| 78 | + * |
| 79 | + * @param SearchIndex $indexDefinition |
| 80 | + * @param UpsertSearchIndexOptions|null $options |
| 81 | + * |
| 82 | + * @since 4.1.7 |
| 83 | + * |
| 84 | + * @VOLATILE: This API is subject to change at any time. |
| 85 | + */ |
| 86 | + public function upsertIndex(SearchIndex $indexDefinition, UpsertSearchIndexOptions $options = null) |
| 87 | + { |
| 88 | + Extension\scopeSearchIndexUpsert($this->core, $this->bucketName, $this->scopeName, SearchIndex::export($indexDefinition), UpsertSearchIndexOptions::export($options)); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Drops a scope-level index from the server |
| 93 | + * |
| 94 | + * @param string $name |
| 95 | + * @param DropSearchIndexOptions|null $options |
| 96 | + * |
| 97 | + * @since 4.1.7 |
| 98 | + * |
| 99 | + * @VOLATILE: This API is subject to change at any time. |
| 100 | + */ |
| 101 | + public function dropIndex(string $name, DropSearchIndexOptions $options = null) |
| 102 | + { |
| 103 | + Extension\scopeSearchIndexDrop($this->core, $this->bucketName, $this->scopeName, $name, DropSearchIndexOptions::export($options)); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Retrieves the number of documents that have been indexed for the scope-level index |
| 108 | + * |
| 109 | + * @param string $indexName |
| 110 | + * @param GetIndexedSearchIndexOptions|null $options |
| 111 | + * |
| 112 | + * @return int |
| 113 | + * @since 4.1.7 |
| 114 | + * |
| 115 | + * @VOLATILE: This API is subject to change at any time. |
| 116 | + */ |
| 117 | + public function getIndexedDocumentsCount(string $indexName, GetIndexedSearchIndexOptions $options = null): int |
| 118 | + { |
| 119 | + $result = Extension\scopeSearchIndexGetDocumentsCount($this->core, $this->bucketName, $this->scopeName, $indexName, GetIndexedSearchIndexOptions::export($options)); |
| 120 | + return $result['count']; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Pauses updates and maintenance for the scope-level index |
| 125 | + * |
| 126 | + * @param string $indexName |
| 127 | + * @param PauseIngestSearchIndexOptions|null $options |
| 128 | + * |
| 129 | + * @since 4.1.7 |
| 130 | + * |
| 131 | + * @VOLATILE: This API is subject to change at any time. |
| 132 | + */ |
| 133 | + public function pauseIngest(string $indexName, PauseIngestSearchIndexOptions $options = null) |
| 134 | + { |
| 135 | + Extension\scopeSearchIndexIngestPause($this->core, $this->bucketName, $this->scopeName, $indexName, PauseIngestSearchIndexOptions::export($options)); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Resumes updates and maintenance for the scope-level index |
| 140 | + * |
| 141 | + * @param string $indexName |
| 142 | + * @param ResumeIngestSearchIndexOptions|null $options |
| 143 | + * |
| 144 | + * @since 4.1.7 |
| 145 | + * |
| 146 | + * @VOLATILE: This API is subject to change at any time. |
| 147 | + */ |
| 148 | + public function resumeIngest(string $indexName, ResumeIngestSearchIndexOptions $options = null) |
| 149 | + { |
| 150 | + Extension\scopeSearchIndexIngestResume($this->core, $this->bucketName, $this->scopeName, $indexName, ResumeIngestSearchIndexOptions::export($options)); |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Allows querying against the scope-level index |
| 155 | + * |
| 156 | + * @param string $indexName |
| 157 | + * @param AllowQueryingSearchIndexOptions|null $options |
| 158 | + * |
| 159 | + * @since 4.1.7 |
| 160 | + * |
| 161 | + * @VOLATILE: This API is subject to change at any time. |
| 162 | + */ |
| 163 | + public function allowQuerying(string $indexName, AllowQueryingSearchIndexOptions $options = null) |
| 164 | + { |
| 165 | + Extension\scopeSearchIndexQueryingAllow($this->core, $this->bucketName, $this->scopeName, $indexName, AllowQueryingSearchIndexOptions::export($options)); |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * Disallows querying against the scope-level index |
| 170 | + * |
| 171 | + * @param string $indexName |
| 172 | + * @param DisallowQueryingSearchIndexOptions|null $options |
| 173 | + * |
| 174 | + * @since 4.1.7 |
| 175 | + * |
| 176 | + * @VOLATILE: This API is subject to change at any time. |
| 177 | + */ |
| 178 | + public function disallowQuerying(string $indexName, DisallowQueryingSearchIndexOptions $options = null) |
| 179 | + { |
| 180 | + Extension\scopeSearchIndexQueryingDisallow($this->core, $this->bucketName, $this->scopeName, $indexName, DisallowQueryingSearchIndexOptions::export($options)); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Freezes the assigment of scope-level index partitions to nodes |
| 185 | + * |
| 186 | + * @param string $indexName |
| 187 | + * @param FreezePlanSearchIndexOptions|null $options |
| 188 | + * |
| 189 | + * @since 4.1.7 |
| 190 | + * |
| 191 | + * @VOLATILE: This API is subject to change at any time. |
| 192 | + */ |
| 193 | + public function freezePlan(string $indexName, FreezePlanSearchIndexOptions $options = null) |
| 194 | + { |
| 195 | + Extension\scopeSearchIndexPlanFreeze($this->core, $this->bucketName, $this->scopeName, $indexName, FreezePlanSearchIndexOptions::export($options)); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * Unfreezes the assignment of index partitions to nodes |
| 200 | + * |
| 201 | + * @param string $indexName |
| 202 | + * @param UnfreezePlanSearchIndexOptions|null $options |
| 203 | + * |
| 204 | + * @since 4.1.7 |
| 205 | + * |
| 206 | + * @VOLATILE: This API is subject to change at any time. |
| 207 | + */ |
| 208 | + public function unfreezePlan(string $indexName, UnfreezePlanSearchIndexOptions $options = null) |
| 209 | + { |
| 210 | + Extension\scopeSearchIndexPlanUnfreeze($this->core, $this->bucketName, $this->scopeName, $indexName, UnfreezePlanSearchIndexOptions::export($options)); |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * Fetches the analysis of a document against a specific scope-level index |
| 215 | + * |
| 216 | + * @param string $indexName |
| 217 | + * @param $document |
| 218 | + * @param AnalyzeDocumentOptions|null $options |
| 219 | + * |
| 220 | + * @return array |
| 221 | + * @since 4.1.7 |
| 222 | + * |
| 223 | + * @VOLATILE: This API is subject to change at any time. |
| 224 | + */ |
| 225 | + public function analyzeDocument(string $indexName, $document, AnalyzeDocumentOptions $options = null): array |
| 226 | + { |
| 227 | + $result = Extension\scopeSearchIndexDocumentAnalyze($this->core, $this->bucketName, $this->scopeName, $indexName, json_encode($document), AnalyzeDocumentOptions::export($options)); |
| 228 | + return json_decode($result["analysis"], true); |
| 229 | + } |
| 230 | +} |
0 commit comments