Commit 813a2930 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Return UUIDs as track IDs

parent 5358c42b
......@@ -168,10 +168,10 @@ class LookupHandler(APIHandler):
response['results'] = results = []
matches = lookup_fingerprint(self.conn, params.fingerprint, params.duration, 0.7, 0.3)
result_map = {}
for fingerprint_id, track_id, score in matches:
for fingerprint_id, track_id, track_gid, score in matches:
if track_id in result_map:
continue
result_map[track_id] = result = {'id': track_id, 'score': score}
result_map[track_id] = result = {'id': track_gid, 'score': score}
results.append(result)
if params.meta and result_map:
self._inject_metadata(params.meta, result_map)
......
......@@ -13,13 +13,13 @@ logger = logging.getLogger(__name__)
FINGERPRINT_VERSION = 1
PARTS = ((1, 20), (21, 100))
PART_SEARCH_SQL = """
SELECT id, track_id, score FROM (
SELECT f.id, f.track_id, t.gid AS track_gid, score FROM (
SELECT id, track_id, acoustid_compare2(fingerprint, query, %(max_offset)s) AS score
FROM fingerprint, (SELECT %(fp)s::int4[] AS query) q
WHERE
length BETWEEN %(length)s - %(max_length_diff)s AND %(length)s + %(max_length_diff)s AND
subarray(acoustid_extract_query(query), %(part_start)s, %(part_length)s) && acoustid_extract_query(fingerprint)
) f WHERE score > %(min_score)s ORDER BY score DESC, id
) f JOIN track t ON f.track_id=t.id WHERE f.score > %(min_score)s ORDER BY f.score DESC, f.id
"""
......
......@@ -99,7 +99,7 @@ INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
handler = LookupHandler(connect=provider(conn))
resp = handler.handle(Request(builder.get_environ()))
assert_equals('text/xml; charset=UTF-8', resp.content_type)
expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><score>1.0</score><id>1</id></result></results></response>"
expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><score>1.0</score><id>eb31d1c3-950e-468b-9e36-e46fa75b1291</id></result></results></response>"
assert_equals(expected, resp.data)
assert_equals('200 OK', resp.status)
# one exact match with MBIDs
......@@ -108,7 +108,7 @@ INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
handler = LookupHandler(connect=provider(conn))
resp = handler.handle(Request(builder.get_environ()))
assert_equals('text/xml; charset=UTF-8', resp.content_type)
expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>1</id></result></results></response>"
expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>eb31d1c3-950e-468b-9e36-e46fa75b1291</id></result></results></response>"
assert_equals(expected, resp.data)
assert_equals('200 OK', resp.status)
# one exact match with MBIDs (no exta metadata in v1)
......@@ -117,7 +117,7 @@ INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
handler = LookupHandler(connect=provider(conn))
resp = handler.handle(Request(builder.get_environ()))
assert_equals('text/xml; charset=UTF-8', resp.content_type)
expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>1</id></result></results></response>"
expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>eb31d1c3-950e-468b-9e36-e46fa75b1291</id></result></results></response>"
#expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><length>123</length><artist><id>a64796c0-4da4-11e0-bf81-0025225356f3</id><name>Artist A</name></artist><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id><releases><release><track_num>1</track_num><id>dd6c2cca-a0e9-4cc4-9a5f-7170bd098e23</id><track_count>2</track_count><name>Album A</name></release></releases><name>Track A</name></track></tracks><score>1.0</score><id>1</id></result></results></response>"
assert_equals(expected, resp.data)
assert_equals('200 OK', resp.status)
......
......@@ -172,7 +172,7 @@ INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
expected = {
"status": "ok",
"results": [{
"id": 1,
"id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
"score": 1.0,
}],
}
......@@ -187,7 +187,7 @@ INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
expected = {
"status": "ok",
"results": [{
"id": 1,
"id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
"score": 1.0,
"recordings": [{"id": "b81f83ee-4da4-11e0-9ed8-0025225356f3"}],
}],
......@@ -204,7 +204,7 @@ INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
expected = {
"status": "ok",
"results": [{
"id": 1,
"id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
"score": 1.0,
"recordings": [{
"id": "373e6728-35e3-4633-aab1-bf7092ec43d8",
......@@ -264,7 +264,7 @@ INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
expected = {
"status": "ok",
"results": [{
"id": 1,
"id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
"score": 1.0,
}],
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment