當前位置: 首頁>>代碼示例>>Python>>正文


Python ES.src2type方法代碼示例

本文整理匯總了Python中nefertari.elasticsearch.ES.src2type方法的典型用法代碼示例。如果您正苦於以下問題:Python ES.src2type方法的具體用法?Python ES.src2type怎麽用?Python ES.src2type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nefertari.elasticsearch.ES的用法示例。


在下文中一共展示了ES.src2type方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_es_mapping

# 需要導入模塊: from nefertari.elasticsearch import ES [as 別名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 別名]
    def get_es_mapping(cls, _depth=None, types_map=None):
        """ Generate ES mapping from model schema. """
        from nefertari.elasticsearch import ES

        if types_map is None:
            types_map = TYPES_MAP

        if _depth is None:
            _depth = cls._nesting_depth

        depth_reached = _depth <= 0

        nested_substitutions = []
        properties = {}
        mapping = {
            ES.src2type(cls.__name__): {
                'properties': properties
            }
        }
        mapper = class_mapper(cls)
        columns = {c.name: c for c in mapper.columns}
        relationships = {r.key: r for r in mapper.relationships}

        for name, column in columns.items():
            column_type = column.type
            if isinstance(column_type, types.ChoiceArray):
                column_type = column_type.impl.item_type
            column_type = type(column_type)
            if column_type not in types_map:
                continue
            properties[name] = types_map[column_type]

            if hasattr(column, "_es_multi_field") and getattr(column, "_es_multi_field"):
                multi_fields = getattr(column, "_es_multi_field")
                properties[name] = properties[name].copy()
                properties[name]["fields"] = {}

                for multi_field_name in multi_fields:
                    properties[name]["fields"][multi_field_name] = multi_fields[multi_field_name].copy()
                    properties[name]["fields"][multi_field_name].update(types_map[column_type])

        for name, column in relationships.items():
            if name in cls._nested_relationships and not depth_reached:
                column_type = {'type': 'nested', 'include_in_parent': True}
                nested_substitutions.append(name)

                submapping, sub_substitutions = column.mapper.class_.get_es_mapping(
                    _depth=_depth - 1)

                column_type.update(list(submapping.values())[0])
                properties[name + "_nested"] = column_type

            rel_pk_field = column.mapper.class_.pk_field_type()
            column_type = types_map[rel_pk_field]
            properties[name] = column_type

        properties['_pk'] = {'type': 'string'}

        return mapping, nested_substitutions
開發者ID:oleduc,項目名稱:nefertari-sqla,代碼行數:61,代碼來源:documents.py

示例2: _get_es_types

# 需要導入模塊: from nefertari.elasticsearch import ES [as 別名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 別名]
def _get_es_types(models):
    """ Get ES types from document model classes.

    :param models: List of document classes.
    :returns: String with ES type names joing by comma.
    """
    type_names = [t.__name__ for t in models
                  if getattr(t, '_index_enabled', False)]
    es_types = [ES.src2type(name) for name in type_names]
    return ','.join(es_types)
開發者ID:geniusproject,項目名稱:nefertari-guards,代碼行數:12,代碼來源:acl_utils.py

示例3: _set_object_self

# 需要導入模塊: from nefertari.elasticsearch import ES [as 別名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 別名]
 def _set_object_self(self, obj):
     """ Add '_self' key value to :obj: dict. """
     from nefertari.elasticsearch import ES
     location = self.request.path_url
     try:
         type_, obj_pk = obj['_type'], obj['_pk']
     except KeyError:
         return
     resource = (self.model_collections.get(type_) or
                 self.model_collections.get(ES.src2type(type_)))
     if resource is not None:
         location = self.request.route_url(
             resource.uid, **{resource.id_name: obj_pk})
     obj.setdefault('_self', location)
開發者ID:mbijon,項目名稱:nefertari,代碼行數:16,代碼來源:wrappers.py

示例4: determine_types

# 需要導入模塊: from nefertari.elasticsearch import ES [as 別名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 別名]
    def determine_types(self):
        """ Determine ES type names from request data.

        In particular `request.matchdict['collections']` is used to
        determine types names. Its value is comma-separated sequence
        of collection names under which views have been registered.
        """
        from nefertari.elasticsearch import ES
        collections = self.get_collections()
        resources = self.get_resources(collections)
        models = set([res.view.Model for res in resources])
        es_models = [mdl for mdl in models if mdl
                     and getattr(mdl, '_index_enabled', False)]
        types = [ES.src2type(mdl.__name__) for mdl in es_models]
        return types
開發者ID:mbijon,項目名稱:nefertari,代碼行數:17,代碼來源:polymorphic.py

示例5: get_es_mapping

# 需要導入模塊: from nefertari.elasticsearch import ES [as 別名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 別名]
    def get_es_mapping(cls, _depth=None, types_map=None):
        """ Generate ES mapping from model schema. """
        from nefertari.elasticsearch import ES
        if types_map is None:
            types_map = TYPES_MAP
        if _depth is None:
            _depth = cls._nesting_depth
        depth_reached = _depth <= 0

        properties = {}
        mapping = {
            ES.src2type(cls.__name__): {
                'properties': properties
            }
        }
        fields = cls._fields.copy()
        for name, field in fields.items():
            if isinstance(field, RelationshipField):
                field = field.field
            if isinstance(field, (ReferenceField, RelationshipField)):
                if name in cls._nested_relationships and not depth_reached:
                    field_mapping = {'type': 'nested'}
                    submapping = field.document_type.get_es_mapping(
                        _depth=_depth-1)
                    field_mapping.update(list(submapping.values())[0])
                else:
                    field_mapping = types_map[
                        field.document_type.pk_field_type()]
                properties[name] = field_mapping
                continue

            if isinstance(field, ChoiceField):
                field = field._real_field
            field_type = type(field)
            if field_type is ListField:
                field_type = field.item_type
            if field_type not in types_map:
                continue
            properties[name] = types_map[field_type]

        properties['_pk'] = {'type': 'string'}
        return mapping
開發者ID:kalyankuramana,項目名稱:nefertari-mongodb,代碼行數:44,代碼來源:documents.py

示例6: _set_object_self

# 需要導入模塊: from nefertari.elasticsearch import ES [as 別名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 別名]
    def _set_object_self(self, obj):
        """ Add '_self' key value to :obj: dict. """
        from nefertari.elasticsearch import ES
        location = self.request.path_url
        route_kwargs = {}

        """ Check for parents """
        if self.request.matchdict:
            route_kwargs.update(self.request.matchdict)
        try:
            type_, obj_pk = obj['_type'], obj['_pk']
        except KeyError:
            return
        resource = (self.model_collections.get(type_) or
                    self.model_collections.get(ES.src2type(type_)))
        if resource is not None:
            route_kwargs.update({resource.id_name: obj_pk})
            location = self.request.route_url(
                resource.uid, **route_kwargs)
        obj.setdefault('_self', location)
開發者ID:mkdir404,項目名稱:nefertari,代碼行數:22,代碼來源:wrappers.py

示例7: get_es_mapping

# 需要導入模塊: from nefertari.elasticsearch import ES [as 別名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 別名]
    def get_es_mapping(cls, _depth=None, types_map=None):
        """ Generate ES mapping from model schema. """
        from nefertari.elasticsearch import ES
        if types_map is None:
            types_map = TYPES_MAP
        if _depth is None:
            _depth = cls._nesting_depth
        depth_reached = _depth <= 0

        properties = {}
        mapping = {
            ES.src2type(cls.__name__): {
                'properties': properties
            }
        }
        mapper = class_mapper(cls)
        columns = {c.name: c for c in mapper.columns}
        relationships = {r.key: r for r in mapper.relationships}

        for name, column in columns.items():
            column_type = column.type
            if isinstance(column_type, types.ChoiceArray):
                column_type = column_type.impl.item_type
            column_type = type(column_type)
            if column_type not in types_map:
                continue
            properties[name] = types_map[column_type]

        for name, column in relationships.items():
            if name in cls._nested_relationships and not depth_reached:
                column_type = {'type': 'nested'}
                submapping = column.mapper.class_.get_es_mapping(
                    _depth=_depth-1)
                column_type.update(list(submapping.values())[0])
            else:
                rel_pk_field = column.mapper.class_.pk_field_type()
                column_type = types_map[rel_pk_field]
            properties[name] = column_type

        properties['_pk'] = {'type': 'string'}
        return mapping
開發者ID:numb3r3,項目名稱:nefertari-sqla,代碼行數:43,代碼來源:documents.py


注:本文中的nefertari.elasticsearch.ES.src2type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。