{
"type": "article",
"docId": "d812aa38f07e",
"tags": [
"queries",
"reply",
"cartel",
"story",
"reviewers"
],
"body": [
{
"text": "Many reviewers are so inundated with queries that they only reply to queries for books they want to review. Some will reply. When they do, thank them for their interest. If they would like to receive the send it to them promptly."
},
{
"YTVideo": "-ZQDTXh9DVA"
},
{
"text": "Another reason to have an — you’ll have your hands busy writing the damn book! That’s where your creative process will make or break you. Take it seriously.These quotations are particularly true when it comes to being successful at self-publishing."
},
{
"text": "This is a great post. I am looking forward for the opportunity to participate in this course. I want to become a better writer, and one day, write a book.The only practice today is to from the Story Cartel Course from the Story Cartel course and read through the first lesson."
}
]
}
Question:
How to make a rating of the most popular (often occurring) tags?
Not every document has a section “text” and a section “tags”.
Elements in the “tags” section can be repeated in different documents.
I want to get the most popular tags.
INSERT INTO default VALUES ("a001", { "type": "article", "docId": "d812aa38f07e", "tags": [ "queries", "reply", "cartel", "story", "reviewers" ], "body": [ { "text": "Many reviewers are so inundated with queries that they only reply to queries for books they want to review. Some will reply. When they do, thank them for their interest. If they would like to receive the send it to them promptly." }, { "YTVideo": "-ZQDTXh9DVA" }, { "text": "Another reason to have an — you’ll have your hands busy writing the damn book! That’s where your creative process will make or break you. Take it seriously.These quotations are particularly true when it comes to being successful at self-publishing." }, { "text": "This is a great post. I am looking forward for the opportunity to participate in this course. I want to become a better writer, and one day, write a book.The only practice today is to from the Story Cartel Course from the Story Cartel course and read through the first lesson." } ] });
CREATE PRIMARY INDEX ON default;
SELECT tag, SUM(ARRAY_LENGTH(ARRAY v FOR v IN SPLIT(b.text) WHEN v = tag END)) AS cnt
FROM default AS d
UNNEST d.tags AS tag
UNNEST d.body AS b
WHERE d.type = "article" AND tag IS NOT NULL AND b.text IS NOT NULL
GROUP BY tag
ORDER BY cnt DESC;