U
    3dR                     @   sp   d dl mZ d dl mZ d dl mZ d dl mZ d dl mZ d dlmZ d dlm	Z	 dd	 Z
G d
d deZdS )    IndexFieldStatus)ServicePoliciesStatusExpressionStatus)AvailabilityOptionsStatus)ScalingParametersStatusDocumentServiceConnectionSearchConnectionc                 C   s   | dkrdS dS )N)TtrueTrueTRUE   TF )valuer   r   </tmp/pip-unpacked-wheel-d7dsrkjd/boto/cloudsearch2/domain.pyhandle_bool    s    r   c                   @   sf  e Zd ZdZdd Zdd Zedd Zedd	 Zed
d Z	edd Z
e
jdd Z
edd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zed d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd?d/d0Zd@d3d4ZdAd5d6Zd7d8 Zd9d: Zd;d< Zd=d> Zd.S )BDomaina  
    A Cloudsearch domain.

    :ivar name: The name of the domain.

    :ivar id: The internally generated unique identifier for the domain.

    :ivar created: A boolean which is True if the domain is
        created. It can take several minutes to initialize a domain
        when CreateDomain is called. Newly created search domains are
        returned with a False value for Created until domain creation
        is complete

    :ivar deleted: A boolean which is True if the search domain has
        been deleted. The system must clean up resources dedicated to
        the search domain when delete is called. Newly deleted
        search domains are returned from list_domains with a True
        value for deleted for several minutes until resource cleanup
        is complete.

    :ivar processing: True if processing is being done to activate the
        current domain configuration.

    :ivar num_searchable_docs: The number of documents that have been
        submittted to the domain and indexed.

    :ivar requires_index_document: True if index_documents needs to be
        called to activate the current domain configuration.

    :ivar search_instance_count: The number of search instances that are
        available to process search requests.

    :ivar search_instance_type: The instance type that is being used to
        process search requests.

    :ivar search_partition_count: The number of partitions across which
        the search index is spread.
    c                 C   s   || _ | | dS )a#  
        Constructor - Create a domain object from a layer1 and data params

        :type layer1: :class:`boto.cloudsearch2.layer1.Layer1` object
        :param layer1: A :class:`boto.cloudsearch2.layer1.Layer1` object
            which is used to perform operations on the domain.
        N)layer1update_from_data)selfr   datar   r   r   __init__N   s    zDomain.__init__c                 C   s   |d | _ |d | _|d | _|d | _|d | _|d | _|d | _|dd | _|d	 | _	|d
 | _
|d | _|d | _d S )NCreatedZDeleted
ProcessingZRequiresIndexDocumentsZDomainIdZ
DomainNameZSearchInstanceCountZSearchInstanceTypeZSearchPartitionCountZ
DocServiceZARNZSearchService)createddeleted
processingrequires_index_documents	domain_iddomain_namesearch_instance_countgetZsearch_instance_typesearch_partition_count_doc_service_service_arn_search_service)r   r   r   r   r   r   Y   s    









zDomain.update_from_datac                 C   s   | j S N)r'   r   r   r   r   service_arng   s    zDomain.service_arnc                 C   s
   | j d S NZEndpoint)r&   r*   r   r   r   doc_service_endpointk   s    zDomain.doc_service_endpointc                 C   s
   | j d S r,   )r(   r*   r   r   r   search_service_endpointo   s    zDomain.search_service_endpointc                 C   s   | j S r)   )_createdr*   r   r   r   r   s   s    zDomain.createdc                 C   s   t || _d S r)   )r   r/   r   r   r   r   r   r   w   s    c                 C   s   | j S r)   )_deletedr*   r   r   r   r   {   s    zDomain.deletedc                 C   s   t || _d S r)   )r   r1   r0   r   r   r   r      s    c                 C   s   | j S r)   )_processingr*   r   r   r   r      s    zDomain.processingc                 C   s   t || _d S r)   )r   r2   r0   r   r   r   r      s    c                 C   s   | j S r)   )_requires_index_documentsr*   r   r   r   r       s    zDomain.requires_index_documentsc                 C   s   t || _d S r)   )r   r3   r0   r   r   r   r       s    c                 C   s   | j S r)   )_search_partition_countr*   r   r   r   r%      s    zDomain.search_partition_countc                 C   s   t || _d S r)   )intr4   r0   r   r   r   r%      s    c                 C   s   | j S r)   )_search_instance_countr*   r   r   r   r#      s    zDomain.search_instance_countc                 C   s   t || _d S r)   )r5   r6   r0   r   r   r   r#      s    c                 C   s   | j S r)   r"   r*   r   r   r   name   s    zDomain.namec                 C   s   | j S r)   )r!   r*   r   r   r   id   s    z	Domain.idc                 C   s   | j | jS )zK
        Delete this domain and all index data associated with it.
        )r   Zdelete_domainr8   r*   r   r   r   delete   s    zDomain.deletec                 C   s   | j | jS )z;
        Return a list of Analysis Scheme objects.
        )r   Zdescribe_analysis_schemesr8   r*   r   r   r   get_analysis_schemes   s    zDomain.get_analysis_schemesc                 C   s   t | | jjdddg| jjdS )a:  
        Return a :class:`boto.cloudsearch2.option.AvailabilityOptionsStatus`
        object representing the currently defined availability options for
        the domain.
        :return: OptionsStatus object
        :rtype: :class:`boto.cloudsearch2.option.AvailabilityOptionsStatus`
            object
        Z#DescribeAvailabilityOptionsResponseZ!DescribeAvailabilityOptionsResultZAvailabilityOptionsZ
refresh_fnZrefresh_keyZsave_fn)r   r   Zdescribe_availability_optionsZupdate_availability_optionsr*   r   r   r   get_availability_options   s    	 zDomain.get_availability_optionsc                 C   s   t | | jjdddg| jjdS )a;  
        Return a :class:`boto.cloudsearch2.option.ScalingParametersStatus`
        object representing the currently defined scaling options for the
        domain.
        :return: ScalingParametersStatus object
        :rtype: :class:`boto.cloudsearch2.option.ScalingParametersStatus`
            object
        Z!DescribeScalingParametersResponseZDescribeScalingParametersResultZScalingParametersr<   )r   r   Zdescribe_scaling_parametersZupdate_scaling_parametersr*   r   r   r   get_scaling_options   s    	 zDomain.get_scaling_optionsc                 C   s   t | | jjdddg| jjdS )a)  
        Return a :class:`boto.cloudsearch2.option.ServicePoliciesStatus`
        object representing the currently defined access policies for the
        domain.
        :return: ServicePoliciesStatus object
        :rtype: :class:`boto.cloudsearch2.option.ServicePoliciesStatus` object
        Z%DescribeServiceAccessPoliciesResponseZ#DescribeServiceAccessPoliciesResultZAccessPoliciesr<   )r   r   Z describe_service_access_policiesZupdate_service_access_policiesr*   r   r   r   get_access_policies   s     zDomain.get_access_policiesc                 C   s   | j | j dS )a*  
        Tells the search domain to start indexing its documents using
        the latest text processing options and IndexFields. This
        operation must be invoked to make options whose OptionStatus
        has OptionState of RequiresIndexDocuments visible in search
        results.
        N)r   index_documentsr8   r*   r   r   r   r@      s    zDomain.index_documentsNc                    s2    j  j|}|d d d } fdd|D S )z
        Return a list of index fields defined for this domain.
        :return: list of IndexFieldStatus objects
        :rtype: list of :class:`boto.cloudsearch2.option.IndexFieldStatus`
            object
        ZDescribeIndexFieldsResponseZDescribeIndexFieldsResultZIndexFieldsc                    s   g | ]}t  |qS r   r   .0dr*   r   r   
<listcomp>   s     z+Domain.get_index_fields.<locals>.<listcomp>)r   describe_index_fieldsr8   )r   field_namesr   r   r*   r   get_index_fields   s    zDomain.get_index_fields Fc                 C   s>  ||d}|dkrH||||d|d< |r4||d d< |	rD|	|d d< n|dkr|||d|d	< |rp||d	 d< |	rd
 |	|d	 d< n|dkr|||||d|d< |r||d d< |	r|	|d d< nD|dkr|||d|d< |r||d d< |	rd
 |	|d d< n|dkrT||||d|d< |r>||d d< |	r|	|d d< n|dkr|||d|d< |r||d d< |	rd
 |	|d d< nr|dkr||||d|d< |r||d d< |	r|	|d d< n.|dkr&|||d|d< |r||d d< |	rd
 |	|d d< n|dkrx|||d|d< |rR||d d< |	rd|	|d d< |
r|
|d d< n|dkr||d|d< |r||d d< |	rd
 |	|d d< |
r|
|d d< n@|d kr||||d|d!< |r||d! d< |	r|	|d! d< | j| j|}|d" d# d$ }t| || jjS )%a  
        Defines an ``IndexField``, either replacing an existing
        definition or creating a new one.

        :type field_name: string
        :param field_name: The name of a field in the search index.

        :type field_type: string
        :param field_type: The type of field.  Valid values are
            int | double | literal | text | date | latlon |
            int-array | double-array | literal-array | text-array | date-array

        :type default: string or int
        :param default: The default value for the field.  If the
            field is of type ``int`` this should be an integer value.
            Otherwise, it's a string.

        :type facet: bool
        :param facet: A boolean to indicate whether facets
            are enabled for this field or not.  Does not apply to
            fields of type ``int, int-array, text, text-array``.

        :type returnable: bool
        :param returnable: A boolean to indicate whether values
            of this field can be returned in search results or
            used in ranking.

        :type searchable: bool
        :param searchable: A boolean to indicate whether search
            is enabled for this field or not.

        :type sortable: bool
        :param sortable: A boolean to indicate whether sorting
            is enabled for this field or not. Does not apply to
            fields of array types.

        :type highlight: bool
        :param highlight: A boolean to indicate whether highlighting
            is enabled for this field or not. Does not apply to
            fields of type ``double, int, date, latlon``

        :type source_field: list of strings or string
        :param source_field: For array types, this is the list of fields
            to treat as the source. For singular types, pass a string only.

        :type analysis_scheme: string
        :param analysis_scheme: The analysis scheme to use for this field.
            Only applies to ``text | text-array`` field types

        :return: IndexFieldStatus objects
        :rtype: :class:`boto.cloudsearch2.option.IndexFieldStatus` object

        :raises: BaseException, InternalException, LimitExceededException,
            InvalidTypeException, ResourceNotFoundException
        )ZIndexFieldNameZIndexFieldTypeliteral)FacetEnabledReturnEnabledSearchEnabledSortEnabledZLiteralOptionsDefaultValueZSourceFieldzliteral-array)rJ   rK   rL   ZLiteralArrayOptions,ZSourceFieldsr5   )rN   rJ   rK   rL   rM   Z
IntOptionsz	int-arrayZIntArrayOptionsdateZDateOptionsz
date-arrayZDateArrayOptionsdoubleZDoubleOptionszdouble-arrayZDoubleArrayOptionstext)rK   HighlightEnabledrM   ZTextOptionsZAnalysisSchemez
text-array)rK   rS   ZTextArrayOptionsZlatlonZLatLonOptionsZDefineIndexFieldResponseZDefineIndexFieldResultZ
IndexField)joinr   Zdefine_index_fieldr8   r   rE   )r   
field_nameZ
field_typedefaultZfacetZ
returnableZ
searchableZsortableZ	highlightZsource_fieldZanalysis_schemeindexr   r   r   r   create_index_field   s    =



















zDomain.create_index_fieldc                    s8   j j  j|}|d d d } fdd|D S )z
        Return a list of rank expressions defined for this domain.
        :return: list of ExpressionStatus objects
        :rtype: list of :class:`boto.cloudsearch2.option.ExpressionStatus`
            object
        ZDescribeExpressionsResponseZDescribeExpressionsResultZExpressionsc                    s   g | ]}t | qS r   r   rA   fnr   r   r   rD     s     z*Domain.get_expressions.<locals>.<listcomp>)r   describe_expressionsr8   )r   namesr   r   rY   r   get_expressions  s    zDomain.get_expressionsc                 C   s2   | j | j||}|d d d }t| || j jS )az
  
        Create a new expression.

        :type name: string
        :param name: The name of an expression for processing
            during a search request.

        :type value: string
        :param value: The expression to evaluate for ranking
            or thresholding while processing a search request. The
            Expression syntax is based on JavaScript expressions
            and supports:

            * Single value, sort enabled numeric fields (int, double, date)
            * Other expressions
            * The _score variable, which references a document's relevance
              score
            * The _time variable, which references the current epoch time
            * Integer, floating point, hex, and octal literals
            * Arithmetic operators: + - * / %
            * Bitwise operators: | & ^ ~ << >> >>>
            * Boolean operators (including the ternary operator): && || ! ?:
            * Comparison operators: < <= == >= >
            * Mathematical functions: abs ceil exp floor ln log2 log10 logn
             max min pow sqrt pow
            * Trigonometric functions: acos acosh asin asinh atan atan2 atanh
             cos cosh sin sinh tanh tan
            * The haversin distance function

            Expressions always return an integer value from 0 to the maximum
            64-bit signed integer value (2^63 - 1). Intermediate results are
            calculated as double-precision floating point values and the return
            value is rounded to the nearest integer. If the expression is
            invalid or evaluates to a negative value, it returns 0. If the
            expression evaluates to a value greater than the maximum, it
            returns the maximum value.

            The source data for an Expression can be the name of an
            IndexField of type int or double, another Expression or the
            reserved name _score. The _score source is
            defined to return as a double from 0 to 10.0 (inclusive) to
            indicate how relevant a document is to the search request,
            taking into account repetition of search terms in the
            document and proximity of search terms to each other in
            each matching IndexField in the document.

            For more information about using rank expressions to
            customize ranking, see the Amazon CloudSearch Developer
            Guide.

        :return: ExpressionStatus object
        :rtype: :class:`boto.cloudsearch2.option.ExpressionStatus` object

        :raises: BaseException, InternalException, LimitExceededException,
            InvalidTypeException, ResourceNotFoundException
        ZDefineExpressionResponseZDefineExpressionResultZ
Expression)r   Zdefine_expressionr8   r   r[   )r   r8   r   r   r   r   r   create_expression  s    9zDomain.create_expressionc                 C   s
   t | dS N)domainr	   r*   r   r   r   get_document_service  s    zDomain.get_document_servicec                 C   s
   t | dS r_   r   r*   r   r   r   get_search_service  s    zDomain.get_search_servicec                 C   s
   d| j  S )Nz<Domain: %s>r7   r*   r   r   r   __repr__  s    zDomain.__repr__)N)rH   FFFFFNN)N) __name__
__module____qualname____doc__r   r   propertyr+   r-   r.   r   setterr   r   r    r%   r#   r8   r9   r:   r;   r=   r>   r?   r@   rG   rX   r]   r^   ra   rb   rc   r   r   r   r   r   &   sv   '


















            
 G
Br   N)Zboto.cloudsearch2.optionstatusr   r   r   r   r   Zboto.cloudsearch2.documentr
   Zboto.cloudsearch2.searchr   r   objectr   r   r   r   r   <module>   s   