def update_automatic_item_matches_by_index(index, item, data): if index in class_map: data = check_data_format(data) matches = get_automatic_item_matches_by_index(index, data) fakeip = 'internal, matched by index {}'.format(index) automatches = data['_geordi']['matchings']['auto_matchings'] changed = False order = [ 'work', 'recording', 'label', 'artist', 'release', 'release_group' ] # Do matches with more linked items first, then supersede with fewer-ID matches for (matchtype, mbids) in sorted(matches.iteritems(), key=lambda x: (len(x[1]), order.index(x[0]) if x[0] in order else 999), reverse=True): if (fakeip not in [match.get('ip') for match in automatches] or ",".join(sorted(mbids)) not in [ ",".join(sorted(match.get('mbid', []))) for match in automatches ]): register_match(index, item, 'item', matchtype, mbids, auto=True, user='******', ip=fakeip) changed = True else: continue return changed
def update_automatic_subitem_matches_by_index(index, item, data): if index in class_map: data = check_data_format(data) matches = get_automatic_subitem_matches_by_index(index, data) fakeip = 'internal, matched by index {}'.format(index) order = ['work', 'recording', 'label', 'artist', 'release', 'release_group'] changed = False for (subitem_id, subitem_matches) in matches.iteritems(): try: document = es.get(index, 'subitem', subitem_id) data = document['_source'] except ElasticHttpNotFoundError: data = {} data = check_data_format(data) automatches = data['_geordi']['matchings']['auto_matchings'] # Do matches with more linked items first, then supersede with fewer-ID matches for (matchtype, mbids) in sorted(subitem_matches.iteritems(), key=lambda x: (len(x[1]), order.index(x[0]) if x[0] in order else 999), reverse=True): if ( fakeip not in [match.get('ip') for match in automatches] or ",".join(sorted(mbids)) not in [",".join(sorted(match.get('mbid', []))) for match in automatches] ): register_match(index, subitem_id, 'subitem', matchtype, mbids, auto=True, user='******', ip=fakeip) changed = True else: continue return changed
def matchsubitem(index, subitem): "Submit a match for this subitem" if get_index(index).matching_enabled(): if current_user.is_authenticated(): auto = False user = None if request.form.get('unmatch', False): return register_match(index, subitem, 'subitem', 'unmatch', [], auto, user) else: auto = True user = request.form.get('user') matchtype = request.form.get('type', 'artist') mbids = request.form.getlist('mbid') if not mbids: mbids = re.split(',\s*', request.form.get('mbids')) return register_match(index, subitem, 'subitem', matchtype, mbids, auto, user) else: return Response(json.dumps({ 'code': 400, 'error': 'Matching is not enabled for this index' }), 400, mimetype="application/json")
def register_matches(index, item_type, item, matches, existing): fakeip = 'internal, matched by index {}'.format(index) changed = False for (matchtype, mbids) in sorted(matches.iteritems(), key=lambda x: (len(x[1]), order.index(x[0]) if x[0] in order else 999), reverse=True): if (fakeip not in [match.get('ip') for match in existing] or ",".join(sorted(mbids)) not in [ ",".join(sorted(match.get('mbid', []))) for match in existing ] or (matchtype == 'unmatch' and len(existing) > 0 and existing[-1]['type'] != 'unmatch') or (not get_index(index).matching_enabled() and existing[-1]['mbid'] != mbids)): register_match(index, item, item_type, matchtype, mbids, auto=True, user='******', ip=fakeip) changed = True else: continue return changed
def matchitem(index, item): "Submit a match for this item" if current_user.is_authenticated(): auto = False user = None if request.args.get('unmatch', False): return register_match(index, item, 'item', 'unmatch', [], auto, user) else: auto = True user = request.args.get('user') if user in ['matched by index']: return Response(json.dumps({ 'code': 400, 'error': 'The name "{}" is reserved.'.format(user) }), 400, mimetype="application/json") matchtype = request.args.get('type', 'release') mbids = request.args.getlist('mbid') if not mbids: mbids = re.split(',\s*', request.args.get('mbids')) return register_match(index, item, 'item', matchtype, mbids, auto, user)
def matchsubitem(index, subitem): "Submit a match for this subitem" if current_user.is_authenticated(): auto = False user = None if request.args.get('unmatch', False): return register_match(index, subitem, 'subitem', 'unmatch', [], auto, user) else: auto = True user = request.args.get('user') matchtype = request.args.get('type', 'artist') mbids = request.args.getlist('mbid') if not mbids: mbids = re.split(',\s*', request.args.get('mbids')) return register_match(index, subitem, 'subitem', matchtype, mbids, auto, user)
def register_matches(index, item_type, item, matches, existing): fakeip = "internal, matched by index {}".format(index) changed = False for (matchtype, mbids) in sorted( matches.iteritems(), key=lambda x: (len(x[1]), order.index(x[0]) if x[0] in order else 999), reverse=True ): if ( fakeip not in [match.get("ip") for match in existing] or ",".join(sorted(mbids)) not in [",".join(sorted(match.get("mbid", []))) for match in existing] or (matchtype == "unmatch" and len(existing) > 0 and existing[-1]["type"] != "unmatch") or (not get_index(index).matching_enabled() and existing[-1]["mbid"] != mbids) ): register_match(index, item, item_type, matchtype, mbids, auto=True, user="******", ip=fakeip) changed = True else: continue return changed
def matchitem(index, item): "Submit a match for this item" if current_user.is_authenticated(): auto = False user = None if request.args.get('unmatch', False): return register_match(index, item, 'item', 'unmatch', [], auto, user) else: auto = True user = request.args.get('user') if user in ['matched by index']: return Response(json.dumps({'code': 400, 'error': 'The name "{}" is reserved.'.format(user)}), 400, mimetype="application/json") matchtype = request.args.get('type', 'release') mbids = request.args.getlist('mbid') if not mbids: mbids = re.split(',\s*', request.args.get('mbids')) return register_match(index, item, 'item', matchtype, mbids, auto, user)
def matchsubitem(index, subitem): "Submit a match for this subitem" if get_index(index).matching_enabled(): if current_user.is_authenticated(): auto = False user = None if request.form.get('unmatch', False): return register_match(index, subitem, 'subitem', 'unmatch', [], auto, user) else: auto = True user = request.form.get('user') matchtype = request.form.get('type', 'artist') mbids = request.form.getlist('mbid') if not mbids: mbids = re.split(',\s*', request.form.get('mbids')) return register_match(index, subitem, 'subitem', matchtype, mbids, auto, user) else: return Response(json.dumps({'code': 400, 'error': 'Matching is not enabled for this index'}), 400, mimetype="application/json")