mirror of
https://github.com/simon987/music-graph-api.git
synced 2025-04-19 09:56:43 +00:00
Graph db endpoints tweaks
This commit is contained in:
parent
6a59ffdeef
commit
1174a0596e
@ -1,14 +1,27 @@
|
|||||||
package net.simon987.musicgraph.entities;
|
package net.simon987.musicgraph.entities;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Release {
|
public class Release {
|
||||||
|
|
||||||
public String mbid;
|
public String mbid;
|
||||||
|
public List<String> labels;
|
||||||
public String name;
|
public String name;
|
||||||
public long year;
|
public long year;
|
||||||
|
public long id;
|
||||||
|
|
||||||
public Release(String mbid, String name, long year) {
|
public Release(List<String> labels, String mbid, String name, long year) {
|
||||||
|
this.labels = labels;
|
||||||
this.mbid = mbid;
|
this.mbid = mbid;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Release(List<String> labels, String mbid, String name, long year, long id) {
|
||||||
|
this.labels = labels;
|
||||||
|
this.mbid = mbid;
|
||||||
|
this.name = name;
|
||||||
|
this.year = year;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,12 @@ package net.simon987.musicgraph.entities;
|
|||||||
|
|
||||||
public class Tag {
|
public class Tag {
|
||||||
public String name;
|
public String name;
|
||||||
public long weight;
|
public double weight;
|
||||||
|
public long id;
|
||||||
|
|
||||||
|
|
||||||
public Tag(String name, long weight) {
|
public Tag(long id, String name, double weight) {
|
||||||
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,8 @@ public class MusicDatabase extends AbstractBinder {
|
|||||||
params.put("mbid", mbid);
|
params.put("mbid", mbid);
|
||||||
|
|
||||||
StatementResult result = query(session,
|
StatementResult result = query(session,
|
||||||
"MATCH (a:Artist)-[r]-(b)\n" +
|
"MATCH (a:Artist)-[r:IS_MEMBER_OF]-(b:Artist) " +
|
||||||
"WHERE a.id = $mbid AND NOT type(r) = \"IS_RELATED_TO\"\n" +
|
"WHERE a.id = $mbid " +
|
||||||
"RETURN a as artist, a {rels: collect(DISTINCT r), nodes: collect(DISTINCT b)} as rank1\n" +
|
"RETURN a as artist, a {rels: collect(DISTINCT r), nodes: collect(DISTINCT b)} as rank1\n" +
|
||||||
"LIMIT 1",
|
"LIMIT 1",
|
||||||
params);
|
params);
|
||||||
@ -79,9 +79,9 @@ public class MusicDatabase extends AbstractBinder {
|
|||||||
|
|
||||||
StatementResult result = query(session,
|
StatementResult result = query(session,
|
||||||
"MATCH (a:Artist {id: $mbid})-[:CREDITED_FOR]->(r:Release)\n" +
|
"MATCH (a:Artist {id: $mbid})-[:CREDITED_FOR]->(r:Release)\n" +
|
||||||
"WITH collect({id:r.id, name:r.name, year:r.year}) as releases, a\n" +
|
"WITH collect({id: ID(r), mbid:r.id, name:r.name, year:r.year, labels:labels(r)}) as releases, a\n" +
|
||||||
"OPTIONAL MATCH (a)-[r:IS_TAGGED]->(t:Tag)\n" +
|
"OPTIONAL MATCH (a)-[r:IS_TAGGED]->(t:Tag)\n" +
|
||||||
"RETURN a {name:a.name, releases:releases, tags:collect({weight: r.weight, name: t.name})}\n" +
|
"RETURN a {name:a.name, releases:releases, tags:collect({weight: r.weight, name: t.name, id:ID(t)})}\n" +
|
||||||
"LIMIT 1",
|
"LIMIT 1",
|
||||||
params);
|
params);
|
||||||
|
|
||||||
@ -97,9 +97,11 @@ public class MusicDatabase extends AbstractBinder {
|
|||||||
((List<Map>) map.get("releases"))
|
((List<Map>) map.get("releases"))
|
||||||
.stream()
|
.stream()
|
||||||
.map(x -> new Release(
|
.map(x -> new Release(
|
||||||
(String) x.get("id"),
|
(List<String>) x.get("labels"),
|
||||||
|
(String) x.get("mbid"),
|
||||||
(String) x.get("name"),
|
(String) x.get("name"),
|
||||||
(Long) x.get("year")
|
(Long) x.get("year"),
|
||||||
|
(Long) x.get("id")
|
||||||
)).collect(Collectors.toList())
|
)).collect(Collectors.toList())
|
||||||
|
|
||||||
);
|
);
|
||||||
@ -108,8 +110,9 @@ public class MusicDatabase extends AbstractBinder {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(x -> x.get("name") != null)
|
.filter(x -> x.get("name") != null)
|
||||||
.map(x -> new Tag(
|
.map(x -> new Tag(
|
||||||
|
(Long) x.get("id"),
|
||||||
(String) x.get("name"),
|
(String) x.get("name"),
|
||||||
(Long) x.get("weight")
|
(Double) x.get("weight")
|
||||||
))
|
))
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
@ -239,7 +242,7 @@ public class MusicDatabase extends AbstractBinder {
|
|||||||
"MATCH (release:Release {id: $mbid})-[:CREDITED_FOR]-(a:Artist)\n" +
|
"MATCH (release:Release {id: $mbid})-[:CREDITED_FOR]-(a:Artist)\n" +
|
||||||
"OPTIONAL MATCH (release)-[r:IS_TAGGED]->(t:Tag)\n" +
|
"OPTIONAL MATCH (release)-[r:IS_TAGGED]->(t:Tag)\n" +
|
||||||
"RETURN release {name:release.name, year:release.year," +
|
"RETURN release {name:release.name, year:release.year," +
|
||||||
"tags:collect({weight:r.weight, name:t.name}), artist: a.name}\n" +
|
"tags:collect({weight:r.weight, name:t.name, id:ID(t)}), artist: a.name}\n" +
|
||||||
"LIMIT 1",
|
"LIMIT 1",
|
||||||
params);
|
params);
|
||||||
|
|
||||||
@ -259,6 +262,7 @@ public class MusicDatabase extends AbstractBinder {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(x -> x.get("name") != null)
|
.filter(x -> x.get("name") != null)
|
||||||
.map(x -> new Tag(
|
.map(x -> new Tag(
|
||||||
|
(Long) x.get("id"),
|
||||||
(String) x.get("name"),
|
(String) x.get("name"),
|
||||||
(Long) x.get("weight")
|
(Long) x.get("weight")
|
||||||
))
|
))
|
||||||
|
@ -44,6 +44,7 @@ public class ArtistController {
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public SearchResult getRelatedByName(@PathParam("name") String name) {
|
public SearchResult getRelatedByName(@PathParam("name") String name) {
|
||||||
|
|
||||||
|
name = name.replace('+', ' ');
|
||||||
logger.info(String.format("Related for %s", name));
|
logger.info(String.format("Related for %s", name));
|
||||||
return db.getRelatedByName(name);
|
return db.getRelatedByName(name);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user