Created
June 24, 2019 15:42
-
-
Save jexp/6cb27cc39c674acc81291646d733aea9 to your computer and use it in GitHub Desktop.
Stackoverflow Import for Neo4j
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
with "graphql" as tagName | |
unwind range(1,10) as page | |
CALL apoc.load.json("https://api.stackexchange.com/2.2/questions?page="+page+"&pagesize=100&order=desc&sort=creation&tagged="+tagName+"&site=stackoverflow&filter=!5-i6Zw8Y)4W7vpy91PMYsKM-k9yzEsSC1_Uxlf") YIELD value | |
call apoc.util.sleep(200) | |
UNWIND value.items AS q | |
with * where not q.question_id is null | |
MERGE (question:Question {id:q.question_id}) | |
SET question.title = q.title, question.link = q.share_link, question.favorites = q.favorite_count, question.upVotes = q.up_vote_count, question.downVotes = q.down_vote_count, question.text = q.body_markdown, question.answered = q.is_answered, | |
question.createdAt = datetime({epochSeconds:q.creation_date}) | |
FOREACH (tagName IN q.tags | MERGE (tag:Tag {name:tagName}) MERGE (question)-[:TAGGED]->(tag)) | |
FOREACH (a IN [a IN q.answers where not a.answer_id is null AND not a.owner.user_id is null] | | |
MERGE (question)<-[:ANSWERS]-(answer:Answer {id:a.answer_id}) | |
SET answer.text = a.body_markdown, answer.createdAt = datetime({epochSeconds:q.creation_date}), answer.link = a.share_link, answer.accepted = a.is_accepted, answer.favorites = a.favorite_count, answer.upVotes = a.up_vote_count, answer.downVotes = a.down_vote_count | |
MERGE (answerer:User {id:a.owner.user_id}) SET answerer.display_name = a.owner.display_name, answerer.reputation = a.owner.reputation, answerer.link = a.owner.link, answerer.image = a.owner.profile_image | |
MERGE (answer)<-[:PROVIDED]-(answerer) | |
) | |
WITH * WHERE NOT q.owner.user_id IS NULL | |
MERGE (owner:User {id:q.owner.user_id}) SET owner.display_name = q.owner.display_name, owner.reputation = q.owner.reputation, owner.link = q.owner.link, owner.image = q.owner.profile_image | |
MERGE (owner)-[:ASKED]->(question) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment