def post_list_search_artifact_json(request, dbp, obj, resource):
    require_permission(request.req, resource, dbp.env)

    unparsed_spec = request.req.args.get('spec', '')
    spec_name = json.loads(unparsed_spec) if unparsed_spec else ''
    attributes = json.loads(request.req.args.get('attributes', '[]'))

    search_results = Searcher.search_artifacts(dbp,
                                               spec=spec_name,
                                               attributes=attributes)
    data = [
        dict({
            'term':
            term,
            'id':
            artifact.get_id(),
            'title':
            unicode(artifact),
            'spec':
            artifact.__class__.get_name()
            if artifact.__class__ != Instance else '',
            'url':
            get_resource_url(
                dbp.env, Resource('asa', artifact.get_id(), artifact.version),
                request.req.href)
        }) for artifact, term in search_results
    ]
    _return_as_json(request, data)
    return
def post_list_search_spec_json(request, dbp, obj, resource):
    require_permission(request.req, resource, dbp.env)

    from AdaptiveArtifacts.persistence.search import Searcher

    term = request.req.args.get('q', '')
    data = Searcher.search_spec_names(dbp, term)
    _return_as_json(request, data)
    return
def post_list_search_spec_json(request, dbp, obj, resource):
    require_permission(request.req, resource, dbp.env)

    from AdaptiveArtifacts.persistence.search import Searcher

    term = request.req.args.get('q', '')
    data = Searcher.search_spec_names(dbp, term)
    _return_as_json(request, data)
    return
def post_list_search_artifact_json(request, dbp, obj, resource):
    require_permission(request.req, resource, dbp.env)

    unparsed_spec = request.req.args.get('spec', '')
    spec_name = json.loads(unparsed_spec) if unparsed_spec else ''
    attributes = json.loads(request.req.args.get('attributes', '[]'))

    search_results = Searcher.search_artifacts(dbp, spec=spec_name, attributes=attributes)
    data = [dict({'term' : term, 'id': artifact.get_id(), 'title': unicode(artifact), 'spec': artifact.__class__.get_name() if artifact.__class__ != Instance else '', 'url':get_resource_url(dbp.env, Resource('asa', artifact.get_id(), artifact.version), request.req.href)}) for artifact, term in search_results]
    _return_as_json(request, data)
    return
    def get_search_results(self, req, terms, filters):
        if 'asa-filter' in filters:
            for a_id, attr_name, attr_value, vid, time, author in Searcher.search(self.env, terms):
                dbp = DBPool(self.env, InstancePool())
                dbp.load_artifact(a_id)
                artifact = dbp.pool.get_item(a_id)

                res = Resource('asa', a_id, vid)
                link = get_resource_url(self.env, res, req.href)
                title = unicode(artifact)
                text = u"Custom Artifact of the type {0}.".format(artifact.__class__.get_name())
                text += u" {0}: {1}".format(attr_name, shorten_result(attr_value, terms))
                yield (link, title, time, author, text)
        return