Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/boto/cloudsearch2/domain.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:18:57 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d30785e31577 |
---|---|
1 # Copyright (c) 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
2 # | |
3 # Permission is hereby granted, free of charge, to any person obtaining a | |
4 # copy of this software and associated documentation files (the | |
5 # "Software"), to deal in the Software without restriction, including | |
6 # without limitation the rights to use, copy, modify, merge, publish, dis- | |
7 # tribute, sublicense, and/or sell copies of the Software, and to permit | |
8 # persons to whom the Software is furnished to do so, subject to the fol- | |
9 # lowing conditions: | |
10 # | |
11 # The above copyright notice and this permission notice shall be included | |
12 # in all copies or substantial portions of the Software. | |
13 # | |
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | |
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
20 # IN THE SOFTWARE. | |
21 # | |
22 | |
23 from boto.cloudsearch2.optionstatus import IndexFieldStatus | |
24 from boto.cloudsearch2.optionstatus import ServicePoliciesStatus | |
25 from boto.cloudsearch2.optionstatus import ExpressionStatus | |
26 from boto.cloudsearch2.optionstatus import AvailabilityOptionsStatus | |
27 from boto.cloudsearch2.optionstatus import ScalingParametersStatus | |
28 from boto.cloudsearch2.document import DocumentServiceConnection | |
29 from boto.cloudsearch2.search import SearchConnection | |
30 | |
31 | |
32 def handle_bool(value): | |
33 if value in [True, 'true', 'True', 'TRUE', 1]: | |
34 return True | |
35 return False | |
36 | |
37 | |
38 class Domain(object): | |
39 """ | |
40 A Cloudsearch domain. | |
41 | |
42 :ivar name: The name of the domain. | |
43 | |
44 :ivar id: The internally generated unique identifier for the domain. | |
45 | |
46 :ivar created: A boolean which is True if the domain is | |
47 created. It can take several minutes to initialize a domain | |
48 when CreateDomain is called. Newly created search domains are | |
49 returned with a False value for Created until domain creation | |
50 is complete | |
51 | |
52 :ivar deleted: A boolean which is True if the search domain has | |
53 been deleted. The system must clean up resources dedicated to | |
54 the search domain when delete is called. Newly deleted | |
55 search domains are returned from list_domains with a True | |
56 value for deleted for several minutes until resource cleanup | |
57 is complete. | |
58 | |
59 :ivar processing: True if processing is being done to activate the | |
60 current domain configuration. | |
61 | |
62 :ivar num_searchable_docs: The number of documents that have been | |
63 submittted to the domain and indexed. | |
64 | |
65 :ivar requires_index_document: True if index_documents needs to be | |
66 called to activate the current domain configuration. | |
67 | |
68 :ivar search_instance_count: The number of search instances that are | |
69 available to process search requests. | |
70 | |
71 :ivar search_instance_type: The instance type that is being used to | |
72 process search requests. | |
73 | |
74 :ivar search_partition_count: The number of partitions across which | |
75 the search index is spread. | |
76 """ | |
77 | |
78 def __init__(self, layer1, data): | |
79 """ | |
80 Constructor - Create a domain object from a layer1 and data params | |
81 | |
82 :type layer1: :class:`boto.cloudsearch2.layer1.Layer1` object | |
83 :param layer1: A :class:`boto.cloudsearch2.layer1.Layer1` object | |
84 which is used to perform operations on the domain. | |
85 """ | |
86 self.layer1 = layer1 | |
87 self.update_from_data(data) | |
88 | |
89 def update_from_data(self, data): | |
90 self.created = data['Created'] | |
91 self.deleted = data['Deleted'] | |
92 self.processing = data['Processing'] | |
93 self.requires_index_documents = data['RequiresIndexDocuments'] | |
94 self.domain_id = data['DomainId'] | |
95 self.domain_name = data['DomainName'] | |
96 self.search_instance_count = data['SearchInstanceCount'] | |
97 self.search_instance_type = data.get('SearchInstanceType', None) | |
98 self.search_partition_count = data['SearchPartitionCount'] | |
99 self._doc_service = data['DocService'] | |
100 self._service_arn = data['ARN'] | |
101 self._search_service = data['SearchService'] | |
102 | |
103 @property | |
104 def service_arn(self): | |
105 return self._service_arn | |
106 | |
107 @property | |
108 def doc_service_endpoint(self): | |
109 return self._doc_service['Endpoint'] | |
110 | |
111 @property | |
112 def search_service_endpoint(self): | |
113 return self._search_service['Endpoint'] | |
114 | |
115 @property | |
116 def created(self): | |
117 return self._created | |
118 | |
119 @created.setter | |
120 def created(self, value): | |
121 self._created = handle_bool(value) | |
122 | |
123 @property | |
124 def deleted(self): | |
125 return self._deleted | |
126 | |
127 @deleted.setter | |
128 def deleted(self, value): | |
129 self._deleted = handle_bool(value) | |
130 | |
131 @property | |
132 def processing(self): | |
133 return self._processing | |
134 | |
135 @processing.setter | |
136 def processing(self, value): | |
137 self._processing = handle_bool(value) | |
138 | |
139 @property | |
140 def requires_index_documents(self): | |
141 return self._requires_index_documents | |
142 | |
143 @requires_index_documents.setter | |
144 def requires_index_documents(self, value): | |
145 self._requires_index_documents = handle_bool(value) | |
146 | |
147 @property | |
148 def search_partition_count(self): | |
149 return self._search_partition_count | |
150 | |
151 @search_partition_count.setter | |
152 def search_partition_count(self, value): | |
153 self._search_partition_count = int(value) | |
154 | |
155 @property | |
156 def search_instance_count(self): | |
157 return self._search_instance_count | |
158 | |
159 @search_instance_count.setter | |
160 def search_instance_count(self, value): | |
161 self._search_instance_count = int(value) | |
162 | |
163 @property | |
164 def name(self): | |
165 return self.domain_name | |
166 | |
167 @property | |
168 def id(self): | |
169 return self.domain_id | |
170 | |
171 def delete(self): | |
172 """ | |
173 Delete this domain and all index data associated with it. | |
174 """ | |
175 return self.layer1.delete_domain(self.name) | |
176 | |
177 def get_analysis_schemes(self): | |
178 """ | |
179 Return a list of Analysis Scheme objects. | |
180 """ | |
181 return self.layer1.describe_analysis_schemes(self.name) | |
182 | |
183 def get_availability_options(self): | |
184 """ | |
185 Return a :class:`boto.cloudsearch2.option.AvailabilityOptionsStatus` | |
186 object representing the currently defined availability options for | |
187 the domain. | |
188 :return: OptionsStatus object | |
189 :rtype: :class:`boto.cloudsearch2.option.AvailabilityOptionsStatus` | |
190 object | |
191 """ | |
192 return AvailabilityOptionsStatus( | |
193 self, refresh_fn=self.layer1.describe_availability_options, | |
194 refresh_key=['DescribeAvailabilityOptionsResponse', | |
195 'DescribeAvailabilityOptionsResult', | |
196 'AvailabilityOptions'], | |
197 save_fn=self.layer1.update_availability_options) | |
198 | |
199 def get_scaling_options(self): | |
200 """ | |
201 Return a :class:`boto.cloudsearch2.option.ScalingParametersStatus` | |
202 object representing the currently defined scaling options for the | |
203 domain. | |
204 :return: ScalingParametersStatus object | |
205 :rtype: :class:`boto.cloudsearch2.option.ScalingParametersStatus` | |
206 object | |
207 """ | |
208 return ScalingParametersStatus( | |
209 self, refresh_fn=self.layer1.describe_scaling_parameters, | |
210 refresh_key=['DescribeScalingParametersResponse', | |
211 'DescribeScalingParametersResult', | |
212 'ScalingParameters'], | |
213 save_fn=self.layer1.update_scaling_parameters) | |
214 | |
215 def get_access_policies(self): | |
216 """ | |
217 Return a :class:`boto.cloudsearch2.option.ServicePoliciesStatus` | |
218 object representing the currently defined access policies for the | |
219 domain. | |
220 :return: ServicePoliciesStatus object | |
221 :rtype: :class:`boto.cloudsearch2.option.ServicePoliciesStatus` object | |
222 """ | |
223 return ServicePoliciesStatus( | |
224 self, refresh_fn=self.layer1.describe_service_access_policies, | |
225 refresh_key=['DescribeServiceAccessPoliciesResponse', | |
226 'DescribeServiceAccessPoliciesResult', | |
227 'AccessPolicies'], | |
228 save_fn=self.layer1.update_service_access_policies) | |
229 | |
230 def index_documents(self): | |
231 """ | |
232 Tells the search domain to start indexing its documents using | |
233 the latest text processing options and IndexFields. This | |
234 operation must be invoked to make options whose OptionStatus | |
235 has OptionState of RequiresIndexDocuments visible in search | |
236 results. | |
237 """ | |
238 self.layer1.index_documents(self.name) | |
239 | |
240 def get_index_fields(self, field_names=None): | |
241 """ | |
242 Return a list of index fields defined for this domain. | |
243 :return: list of IndexFieldStatus objects | |
244 :rtype: list of :class:`boto.cloudsearch2.option.IndexFieldStatus` | |
245 object | |
246 """ | |
247 data = self.layer1.describe_index_fields(self.name, field_names) | |
248 | |
249 data = (data['DescribeIndexFieldsResponse'] | |
250 ['DescribeIndexFieldsResult'] | |
251 ['IndexFields']) | |
252 | |
253 return [IndexFieldStatus(self, d) for d in data] | |
254 | |
255 def create_index_field(self, field_name, field_type, | |
256 default='', facet=False, returnable=False, | |
257 searchable=False, sortable=False, | |
258 highlight=False, source_field=None, | |
259 analysis_scheme=None): | |
260 """ | |
261 Defines an ``IndexField``, either replacing an existing | |
262 definition or creating a new one. | |
263 | |
264 :type field_name: string | |
265 :param field_name: The name of a field in the search index. | |
266 | |
267 :type field_type: string | |
268 :param field_type: The type of field. Valid values are | |
269 int | double | literal | text | date | latlon | | |
270 int-array | double-array | literal-array | text-array | date-array | |
271 | |
272 :type default: string or int | |
273 :param default: The default value for the field. If the | |
274 field is of type ``int`` this should be an integer value. | |
275 Otherwise, it's a string. | |
276 | |
277 :type facet: bool | |
278 :param facet: A boolean to indicate whether facets | |
279 are enabled for this field or not. Does not apply to | |
280 fields of type ``int, int-array, text, text-array``. | |
281 | |
282 :type returnable: bool | |
283 :param returnable: A boolean to indicate whether values | |
284 of this field can be returned in search results or | |
285 used in ranking. | |
286 | |
287 :type searchable: bool | |
288 :param searchable: A boolean to indicate whether search | |
289 is enabled for this field or not. | |
290 | |
291 :type sortable: bool | |
292 :param sortable: A boolean to indicate whether sorting | |
293 is enabled for this field or not. Does not apply to | |
294 fields of array types. | |
295 | |
296 :type highlight: bool | |
297 :param highlight: A boolean to indicate whether highlighting | |
298 is enabled for this field or not. Does not apply to | |
299 fields of type ``double, int, date, latlon`` | |
300 | |
301 :type source_field: list of strings or string | |
302 :param source_field: For array types, this is the list of fields | |
303 to treat as the source. For singular types, pass a string only. | |
304 | |
305 :type analysis_scheme: string | |
306 :param analysis_scheme: The analysis scheme to use for this field. | |
307 Only applies to ``text | text-array`` field types | |
308 | |
309 :return: IndexFieldStatus objects | |
310 :rtype: :class:`boto.cloudsearch2.option.IndexFieldStatus` object | |
311 | |
312 :raises: BaseException, InternalException, LimitExceededException, | |
313 InvalidTypeException, ResourceNotFoundException | |
314 """ | |
315 index = { | |
316 'IndexFieldName': field_name, | |
317 'IndexFieldType': field_type | |
318 } | |
319 if field_type == 'literal': | |
320 index['LiteralOptions'] = { | |
321 'FacetEnabled': facet, | |
322 'ReturnEnabled': returnable, | |
323 'SearchEnabled': searchable, | |
324 'SortEnabled': sortable | |
325 } | |
326 if default: | |
327 index['LiteralOptions']['DefaultValue'] = default | |
328 if source_field: | |
329 index['LiteralOptions']['SourceField'] = source_field | |
330 elif field_type == 'literal-array': | |
331 index['LiteralArrayOptions'] = { | |
332 'FacetEnabled': facet, | |
333 'ReturnEnabled': returnable, | |
334 'SearchEnabled': searchable | |
335 } | |
336 if default: | |
337 index['LiteralArrayOptions']['DefaultValue'] = default | |
338 if source_field: | |
339 index['LiteralArrayOptions']['SourceFields'] = \ | |
340 ','.join(source_field) | |
341 elif field_type == 'int': | |
342 index['IntOptions'] = { | |
343 'DefaultValue': default, | |
344 'FacetEnabled': facet, | |
345 'ReturnEnabled': returnable, | |
346 'SearchEnabled': searchable, | |
347 'SortEnabled': sortable | |
348 } | |
349 if default: | |
350 index['IntOptions']['DefaultValue'] = default | |
351 if source_field: | |
352 index['IntOptions']['SourceField'] = source_field | |
353 elif field_type == 'int-array': | |
354 index['IntArrayOptions'] = { | |
355 'FacetEnabled': facet, | |
356 'ReturnEnabled': returnable, | |
357 'SearchEnabled': searchable | |
358 } | |
359 if default: | |
360 index['IntArrayOptions']['DefaultValue'] = default | |
361 if source_field: | |
362 index['IntArrayOptions']['SourceFields'] = \ | |
363 ','.join(source_field) | |
364 elif field_type == 'date': | |
365 index['DateOptions'] = { | |
366 'FacetEnabled': facet, | |
367 'ReturnEnabled': returnable, | |
368 'SearchEnabled': searchable, | |
369 'SortEnabled': sortable | |
370 } | |
371 if default: | |
372 index['DateOptions']['DefaultValue'] = default | |
373 if source_field: | |
374 index['DateOptions']['SourceField'] = source_field | |
375 elif field_type == 'date-array': | |
376 index['DateArrayOptions'] = { | |
377 'FacetEnabled': facet, | |
378 'ReturnEnabled': returnable, | |
379 'SearchEnabled': searchable | |
380 } | |
381 if default: | |
382 index['DateArrayOptions']['DefaultValue'] = default | |
383 if source_field: | |
384 index['DateArrayOptions']['SourceFields'] = \ | |
385 ','.join(source_field) | |
386 elif field_type == 'double': | |
387 index['DoubleOptions'] = { | |
388 'FacetEnabled': facet, | |
389 'ReturnEnabled': returnable, | |
390 'SearchEnabled': searchable, | |
391 'SortEnabled': sortable | |
392 } | |
393 if default: | |
394 index['DoubleOptions']['DefaultValue'] = default | |
395 if source_field: | |
396 index['DoubleOptions']['SourceField'] = source_field | |
397 elif field_type == 'double-array': | |
398 index['DoubleArrayOptions'] = { | |
399 'FacetEnabled': facet, | |
400 'ReturnEnabled': returnable, | |
401 'SearchEnabled': searchable | |
402 } | |
403 if default: | |
404 index['DoubleArrayOptions']['DefaultValue'] = default | |
405 if source_field: | |
406 index['DoubleArrayOptions']['SourceFields'] = \ | |
407 ','.join(source_field) | |
408 elif field_type == 'text': | |
409 index['TextOptions'] = { | |
410 'ReturnEnabled': returnable, | |
411 'HighlightEnabled': highlight, | |
412 'SortEnabled': sortable | |
413 } | |
414 if default: | |
415 index['TextOptions']['DefaultValue'] = default | |
416 if source_field: | |
417 index['TextOptions']['SourceField'] = source_field | |
418 if analysis_scheme: | |
419 index['TextOptions']['AnalysisScheme'] = analysis_scheme | |
420 elif field_type == 'text-array': | |
421 index['TextArrayOptions'] = { | |
422 'ReturnEnabled': returnable, | |
423 'HighlightEnabled': highlight | |
424 } | |
425 if default: | |
426 index['TextArrayOptions']['DefaultValue'] = default | |
427 if source_field: | |
428 index['TextArrayOptions']['SourceFields'] = \ | |
429 ','.join(source_field) | |
430 if analysis_scheme: | |
431 index['TextArrayOptions']['AnalysisScheme'] = analysis_scheme | |
432 elif field_type == 'latlon': | |
433 index['LatLonOptions'] = { | |
434 'FacetEnabled': facet, | |
435 'ReturnEnabled': returnable, | |
436 'SearchEnabled': searchable, | |
437 'SortEnabled': sortable | |
438 } | |
439 if default: | |
440 index['LatLonOptions']['DefaultValue'] = default | |
441 if source_field: | |
442 index['LatLonOptions']['SourceField'] = source_field | |
443 | |
444 data = self.layer1.define_index_field(self.name, index) | |
445 | |
446 data = (data['DefineIndexFieldResponse'] | |
447 ['DefineIndexFieldResult'] | |
448 ['IndexField']) | |
449 | |
450 return IndexFieldStatus(self, data, | |
451 self.layer1.describe_index_fields) | |
452 | |
453 def get_expressions(self, names=None): | |
454 """ | |
455 Return a list of rank expressions defined for this domain. | |
456 :return: list of ExpressionStatus objects | |
457 :rtype: list of :class:`boto.cloudsearch2.option.ExpressionStatus` | |
458 object | |
459 """ | |
460 fn = self.layer1.describe_expressions | |
461 data = fn(self.name, names) | |
462 | |
463 data = (data['DescribeExpressionsResponse'] | |
464 ['DescribeExpressionsResult'] | |
465 ['Expressions']) | |
466 | |
467 return [ExpressionStatus(self, d, fn) for d in data] | |
468 | |
469 def create_expression(self, name, value): | |
470 """ | |
471 Create a new expression. | |
472 | |
473 :type name: string | |
474 :param name: The name of an expression for processing | |
475 during a search request. | |
476 | |
477 :type value: string | |
478 :param value: The expression to evaluate for ranking | |
479 or thresholding while processing a search request. The | |
480 Expression syntax is based on JavaScript expressions | |
481 and supports: | |
482 | |
483 * Single value, sort enabled numeric fields (int, double, date) | |
484 * Other expressions | |
485 * The _score variable, which references a document's relevance | |
486 score | |
487 * The _time variable, which references the current epoch time | |
488 * Integer, floating point, hex, and octal literals | |
489 * Arithmetic operators: + - * / % | |
490 * Bitwise operators: | & ^ ~ << >> >>> | |
491 * Boolean operators (including the ternary operator): && || ! ?: | |
492 * Comparison operators: < <= == >= > | |
493 * Mathematical functions: abs ceil exp floor ln log2 log10 logn | |
494 max min pow sqrt pow | |
495 * Trigonometric functions: acos acosh asin asinh atan atan2 atanh | |
496 cos cosh sin sinh tanh tan | |
497 * The haversin distance function | |
498 | |
499 Expressions always return an integer value from 0 to the maximum | |
500 64-bit signed integer value (2^63 - 1). Intermediate results are | |
501 calculated as double-precision floating point values and the return | |
502 value is rounded to the nearest integer. If the expression is | |
503 invalid or evaluates to a negative value, it returns 0. If the | |
504 expression evaluates to a value greater than the maximum, it | |
505 returns the maximum value. | |
506 | |
507 The source data for an Expression can be the name of an | |
508 IndexField of type int or double, another Expression or the | |
509 reserved name _score. The _score source is | |
510 defined to return as a double from 0 to 10.0 (inclusive) to | |
511 indicate how relevant a document is to the search request, | |
512 taking into account repetition of search terms in the | |
513 document and proximity of search terms to each other in | |
514 each matching IndexField in the document. | |
515 | |
516 For more information about using rank expressions to | |
517 customize ranking, see the Amazon CloudSearch Developer | |
518 Guide. | |
519 | |
520 :return: ExpressionStatus object | |
521 :rtype: :class:`boto.cloudsearch2.option.ExpressionStatus` object | |
522 | |
523 :raises: BaseException, InternalException, LimitExceededException, | |
524 InvalidTypeException, ResourceNotFoundException | |
525 """ | |
526 data = self.layer1.define_expression(self.name, name, value) | |
527 | |
528 data = (data['DefineExpressionResponse'] | |
529 ['DefineExpressionResult'] | |
530 ['Expression']) | |
531 | |
532 return ExpressionStatus(self, data, | |
533 self.layer1.describe_expressions) | |
534 | |
535 def get_document_service(self): | |
536 return DocumentServiceConnection(domain=self) | |
537 | |
538 def get_search_service(self): | |
539 return SearchConnection(domain=self) | |
540 | |
541 def __repr__(self): | |
542 return '<Domain: %s>' % self.domain_name |