Skip to content

Commit

Permalink
Allow arbitrary depth in taxonomy tagging
Browse files Browse the repository at this point in the history
This now assembles all the taxons that content is tagged to, whether directly,
or via taxonomy inheritance.  It then checks to see if any of those are
priority taxons.
  • Loading branch information
sihugh committed May 23, 2020
1 parent 98bfb13 commit b35f461
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ def taxon
private

def priority_taxons
taxons = []
content_item.dig("links", "taxons")&.map do |taxon|
taxons << taxon if priority_taxon?(taxon)

taxons << taxon.dig("links", "parent_taxons")&.select do |parent_taxon|
priority_taxon?(parent_taxon)
end
taxons = content_item.dig("links", "taxons")
taxon_tree(taxons).select do |taxon|
priority_taxon?(taxon)
end
end

def taxon_tree(taxons)
return [] if taxons.blank?

taxons.flatten!
taxons.compact!
taxons
taxons + taxons.flat_map { |taxon| taxon_tree(taxon.dig("links", "parent_taxons")) }
end

def priority_taxon?(taxon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
end
end


def directly_tagged_to_taxons(taxons)
taxons << other_taxon
{
Expand Down

0 comments on commit b35f461

Please sign in to comment.