Exemplo n.º 1
0
Arquivo: docs.py Projeto: szkocka/api
    def find(cls, keyword, status, tag, page):
        page_size = int(os.environ['PAGE_SIZE'])
        offset = page_size * int(page)

        query = 'title:*'
        if keyword:
            query = keyword.encode('utf-8').strip()

        if status:
            query += ' AND status:{0}'.format(status)
        if tag:
            encoded_tag = tag.encode('utf-8').strip()
            query += ' AND tags:{0}'.format(encoded_tag)

        search_query = search.Query(
                query_string=query.strip(),
                options=search.QueryOptions(ids_only=True,
                                            limit=page_size,
                                            offset=offset)
        )

        logging.info(query)
        results = RESEARCH_INDEX.search(search_query).results

        found_researches = map(lambda r: Research.get(int(r.doc_id)), results)

        return filter(lambda r: r.status != StatusType.DELETED, found_researches)
Exemplo n.º 2
0
Arquivo: tasks.py Projeto: szkocka/api
    def post(self):
        research_id = int(request.json['research_id'])
        research = Research.get(research_id)

        ResearchIndex(research).put()

        return ok_msg('Research indexed.')
Exemplo n.º 3
0
    def wrapper(*args, **kwargs):
        if 'research_id' not in kwargs:
            return bad_request('To use insert_research wrapper research_id must be in url.')

        _id = kwargs['research_id']
        research = Research.get(int(_id))

        if research is None:
            return research_not_found(_id)

        del kwargs['research_id']
        kwargs['research'] = research

        return func(*args, **kwargs)