Exemplo n.º 1
0
    def search(self):
        ids = [self.root_id
               ] if not isinstance(self.root_id, list) else self.root_id
        cis = [
            CI.get_by_id(_id)
            or abort(404, "CI <{0}> does not exist".format(_id)) for _id in ids
        ]

        merge_ids = []
        for level in self.level:
            ids = [self.root_id
                   ] if not isinstance(self.root_id, list) else self.root_id
            for _ in range(0, level):
                _tmp = list(
                    map(
                        lambda x: list(json.loads(x).keys()),
                        filter(lambda x: x is not None,
                               rd.get(ids, REDIS_PREFIX_CI_RELATION) or [])))
                ids = [j for i in _tmp for j in i]

            merge_ids.extend(ids)

        if not self.orig_query or ("_type:" not in self.orig_query
                                   and "type_id:" not in self.orig_query
                                   and "ci_type:" not in self.orig_query):
            type_ids = []
            for level in self.level:
                for ci in cis:
                    type_ids.extend(
                        CITypeRelationManager.get_child_type_ids(
                            ci.type_id, level))
            type_ids = list(set(type_ids))
            if self.orig_query:
                self.orig_query = "_type:({0}),{1}".format(
                    ";".join(list(map(str, type_ids))), self.orig_query)
            else:
                self.orig_query = "_type:({0})".format(";".join(
                    list(map(str, type_ids))))

        if not merge_ids:
            # cis, counter, total, self.page, numfound, facet_
            return [], {}, 0, self.page, 0, {}

        if current_app.config.get("USE_ES"):
            return SearchFromES(self.orig_query,
                                fl=self.fl,
                                facet_field=self.facet_field,
                                page=self.page,
                                count=self.count,
                                sort=self.sort,
                                ci_ids=merge_ids).search()
        else:
            return SearchFromDB(self.orig_query,
                                fl=self.fl,
                                facet_field=self.facet_field,
                                page=self.page,
                                count=self.count,
                                sort=self.sort,
                                ci_ids=merge_ids).search()
Exemplo n.º 2
0
    def delete(self, ctr_id):
        CITypeRelationManager.delete(ctr_id)

        return self.jsonify(code=200, ctr_id=ctr_id)
Exemplo n.º 3
0
    def delete(self, parent_id, child_id):
        CITypeRelationManager.delete_2(parent_id, child_id)

        return self.jsonify(code=200, parent_id=parent_id, child_id=child_id)
Exemplo n.º 4
0
    def post(self, parent_id, child_id):
        relation_type_id = request.values.get("relation_type_id")
        ctr_id = CITypeRelationManager.add(parent_id, child_id, relation_type_id)

        return self.jsonify(ctr_id=ctr_id)
Exemplo n.º 5
0
    def get(self):
        res = CITypeRelationManager.get()

        return self.jsonify(res)
Exemplo n.º 6
0
 def get(self, child_id):
     return self.jsonify(parents=CITypeRelationManager.get_parents(child_id))
Exemplo n.º 7
0
 def get(self, parent_id):
     return self.jsonify(children=CITypeRelationManager.get_children(parent_id))