def handle_get(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=ReleaseGroupIncludes.parse) release_group = get_release_group_by_gid(query_release_group(g.db, include), gid) if release_group is None: abort(response_error(NOT_FOUND_ERROR, 'release group not found')) return response_ok(release_group=serialize_release_group(release_group, include))
def handle_get(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=WorkIncludes.parse) work = get_work_by_gid(query_work(g.db, include), gid) if work is None: abort(response_error(NOT_FOUND_ERROR, 'work not found')) if include.relationships: load_links(g.db, [work], include.relationships) return response_ok(work=serialize_work(work, include))
def handle_list_releases(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=ReleaseIncludes.parse) release_group_query = g.db.query(ReleaseGroup.id).filter_by(gid=gid).as_scalar() query = query_release(g.db, include).\ filter(Release.release_group_id == release_group_query).\ order_by(Release.id).limit(10) # FIXME releases_data = [] for release in query: releases_data.append(serialize_release(release, include)) return response_ok(releases=releases_data)
def handle_get(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=ReleaseIncludes.parse) if include.artist and include.artists: abort(response_error(INCLUDE_DEPENDENCY_ERROR, 'include=artist and include=artists are mutually exclusive')) release = get_release_by_gid(query_release(g.db, include), gid) if release is None: abort(response_error(NOT_FOUND_ERROR, 'release not found')) if include.relationships: load_links(g.db, [release], include.relationships) return response_ok(release=serialize_release(release, include))
def handle_get(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=PlaceIncludes.parse) place = get_place_by_gid(query_place(g.db, include), gid) if place is None: abort(response_error(NOT_FOUND_ERROR, 'place not found')) if include.area: load_areas(g.db, [place], include.area) if include.relationships: load_links(g.db, [place], include.relationships) return response_ok(place=serialize_place(place, include))
def handle_get(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=ArtistIncludes.parse) artist = get_artist_by_gid(query_artist(g.db, include), gid) if artist is None: abort(response_error(NOT_FOUND_ERROR, 'artist not found')) if include.areas: load_areas(g.db, [artist], include.areas) if include.relationships: load_links(g.db, [artist], include.relationships) return response_ok(artist=serialize_artist(artist, include))
def handle_list_releases(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=ReleaseIncludes.parse) artist = get_plain_artist_by_gid_or_error(gid) artist_credits_query = g.db.query(ArtistCreditName.artist_credit_id).\ filter_by(artist_id=artist.id) query = query_release(g.db, include).\ filter(Release.artist_credit_id.in_(artist_credits_query)).\ order_by(Release.id).limit(10) # FIXME releases_data = [] for release in query: releases_data.append(serialize_release(release, include)) return response_ok(releases=releases_data)
def handle_search(): query = get_param('query', type='text') include = get_param('include', type='enum+', container=ArtistIncludes.parse) page = get_search_params() options = prepare_search_options(page, fields='name^1.6 sort_name^1.1 alias') search_results = g.solr.select(query, fq='kind:artist', **options) # http://127.0.0.1:8983/solr/musicbrainz/select?q=gender:male&group=true&group.field=kind&group.limit=3&defType=edismax&qf=name&uf=* artist_ids = [] scores = {} for result in search_results: id = int(result['id'].split(':', 1)[1]) artist_ids.append(id) scores[id] = result['score'] artists = query_artist(g.db, include).filter(Artist.id.in_(artist_ids)) artist_by_id = {} for artist in artists: artist_by_id[artist.id] = artist if include.areas: load_areas(g.db, artist_by_id.values(), include.areas) data = [] for id in artist_ids: data.append({ 'score': scores[id], 'artist': serialize_artist(artist_by_id[id], include), }) return response_ok(results=data, page_info=prepare_page_info(search_results, page))