Last active
May 14, 2021 17:23
-
-
Save BryantAvey/af1bb0cb2542c7829dab947e2dc97daa to your computer and use it in GitHub Desktop.
Neo4j Cypher - Generate Blog Article and Category with Relationships From any Blog Feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CALL apoc.load.xml("https://www.starwars.com/news/feed", "rss/channel/item") | |
YIELD value | |
WITH [child in value._children WHERE child._type = "title" | child._text][0] AS title, | |
[child in value._children WHERE child._type = "link" | child._text][0] AS guid, | |
apoc.text.regreplace( | |
[child in value._children WHERE child._type = "description" | child._text][0], | |
'<[^>]*>', | |
' ' | |
) AS body, | |
[child in value._children WHERE child._type = "category" | child._text] AS categories | |
MERGE (a:Article {id: guid}) | |
SET a.body = body, a.title = title, a.blog = "StarWars.com" | |
WITH a, categories | |
CALL { | |
WITH a, categories | |
UNWIND categories AS category | |
MERGE (c:Category {name: category}) | |
MERGE (a)-[:IN_CATEGORY]->(c) | |
RETURN count(*) AS categoryCount | |
} | |
RETURN a.id AS articleId, a.title AS title, categoryCount; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment