title: string @index(term) .
term: string @index(term) .
category: string @index(term) .
has_category: uid @reverse .
has_term: [uid] @reverse .
type Category {
category
}
type Term {
term
}
type Article {
title
has_category
has_term
}
With the following relationships:
Article → (has_category) → Category
Article → (has_term with has_term|appears facet) → Term
What I am trying to achieve is map back from a list of terms to their categories. Once I have that, I want to groupby term + category to calculate total sum of appears facet.
The closest I got is:
query main($text: string){
q(func: anyofterms(term, $text), first: 2) @filter(eq(dgraph.type, "Term")) {
term: term
~has_term @normalize {
title
has_category {
category:category
}
appears: val(a)
} @facets (a as appears)
}
}
Not quite. I can’t sum the appears value as I want it to be grouped by category (a term can belong to multiple categories). I want the has_term array to combine entries that have the same category and combine the has_terms|appears value. With the current state we have something like this:
term | category | appears
health | Health | 3
health | Health | 2
health | Insurance | 1
I’d like:
term | category | appears
health | Health | 5
health | Insurance | 1
If this is not possible I’ll just have to do this in code.