-
-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include charts' parent tags in the algolia index #3790
Conversation
Quick links (staging server):
Login:
SVG tester:Number of differences (default views): 0 ✅ Edited: 2024-07-12 22:27:06 UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but suggestion to push more into SQL.
]) | ||
} | ||
|
||
trackParents(tagGraph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that this code works, but the structure of how we're building and working with this graph is more complex than it needs to be.
For example, you need to build the graph twice, once flat, once with the object model, and you also need to do a second query to fetch the tag names. You have to rewrite the parents multiple times instead of computing it just once.
A more standard graph representation would be something like idToNode
(and maybe idToChildIds
or idToParentId
), and would make the subsequent traversal much easier. Then you also skip entirely the fake root node.
In this case, the flat tag graph is basically idToChildNodes
, plus the root id. The graph would be better if it was just idToNode
, ungrouped, since the node already contains the parent id. Let's imagine that scenario.
const idToNode = getFlatTagGraph(trx)
const tagNameToParentTags = {}
for (const node of Object.values(idToNode)) {
const name = node.name
const parents = []
let parentId = node.parentId
while (parentId) {
const parent = idToNode[parentId]
parents.append(name)
parentId = parent.parentId
}
tagNameToParentTags[name] = parents
}
It becomes easy to iterate across every node, and easy to follow the parent chain for every node too.
How much would that mess up other code elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe #3800 might be adding some confusion here 😛
A few things:
- With the
tag_graph
table (not the tags'parentId
column) a node can have multiple parents:
-
The fake root node was added as a simple way to coexist with a
tags
table that has non-topic/area tags in it. Anything that's a child of the root tag node is part of the graph. Things that aren't (e.g.Abstract
) can be ignored. -
If I hadn't already written code for the tag graph UI, I could have written this function with
idToParentIds
andidToNode
maps, but given I had those 2 functions already (which, if you squint, create the same data structure) it seemed simpler at the time to do it this way.
We should have a call about this to make sure I'm understanding you correctly though. 🙂
Part of #3781
Adds a new function that finds all ancestors of a given tag and includes them in a chart's record when we index to Algolia.
Examples
tag
value of["Cardiovascular Diseases"]
will now have["Cardiovascular Diseases", "Health"]
tag
value of["Indoor Air Pollution", "CO2 & Greenhouse Gas Emissions"]
will now have["Indoor Air Pollution", "CO2 & Greenhouse Gas Emissions", "Air Pollution", "Health", "Energy and Environment"]
Example output of
getParentTagsByChildName