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)
def get(self, current_user): relationship_types = get_relationship_types(current_user) cursor = request.args.get('cursor') researches, cursor, _ = Research.all(cursor) return ok(ListResearchesJson(researches, relationship_types, cursor))
def reindex_all(cls): for r in Research.all2(): r_index = ResearchIndex(r) r_index.delete() if r.status == StatusType.ACTIVE: r_index.put()
def post(self): research_id = int(request.json['research_id']) research = Research.get(research_id) ResearchIndex(research).put() return ok_msg('Research indexed.')
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)
def get(self): tags = Research.all_tags() return ok(TagsJson(tags))
def get(self, current_user, user): relationship_types = get_relationship_types(user) cursor = request.args.get('cursor') users, cursor, _ = Research.by_user(user.key, cursor) return ok(ListUserResearchesJson(users, relationship_types, cursor))
def get(self, current_user, user): supervisor_of = Research.by_supervisor(user.key) researcher_in = Research.by_researcher(user.key) return ok(UserDetailsJson(user, supervisor_of, researcher_in))