![]() |
#1 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Removing hierarchy levels
I created a list_union composite to separate the hierarchical tags and make it look neater in the details view.
I actually got it working as I expected (e.g. Fiction.Animals.Cats, Fiction.Mystery.Cozy Mystery becomes Fiction, Animals, Cats, Mystery, Cozy Mystery). However, how would I strip out any sublevel items under specific tags? e.g. Fanfiction.Crossover and Documentation and Manuals.Video Games.Strategy Guides, I just want the top levels to appear. (I have them grouped in general broad tags and use custom manual/fanfic-specific columns for actual filtering.) I thought list_difference would work but I'm not really sure what I'm doing: Code:
{tags:'list_difference(re($, '\.', ', '), 'Fanfiction', ',')'} Code:
{tags:'list_difference(re($, '\.', ', '), 'Fanfiction.Crossover, ',')'} Code:
{tags:'list_difference(re($, '\.', ', '), 'Crossover, ',')'} ![]() Last edited by ownedbycats; 12-21-2020 at 05:21 AM. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Moderator Notice
Moved to separate thread |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
If I understand you correctly you want to remove the second - last part of hierarchical items in a field. This template does that.
Code:
{#genre:'list_re($, ',', '^(.*?)($|\..*$)', '\1')'} |
![]() |
![]() |
![]() |
#4 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Unfortunately, that removed subitems from all my books.
![]() I just want to remove any subitems from a hierarchical item beginning with Fanfiction or Documentation and Manuals. Alternately, hiding it entirely if that's easier. At the very least the third list_difference in the OP works, though I just have to add all the items manually (and make sure they're not used elsewhere). Last edited by ownedbycats; 12-21-2020 at 06:17 AM. |
![]() |
![]() |
![]() |
#5 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: g = field('#genre'); list_re_group(g, ',', '.', '^(Fanfiction|Documentation and Manuals)($|\..*$)', '{$}', '') |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
That's close to what I was trying to do, though now it causes tags to display unsplit.
Hopefully this explains better what I'm trying to do: Tags: Fiction.Animals.Cats, Fiction.Mystery.Cozy Mystery Results: Fiction, Animals, Cats, Mystery, Cozy Mystery (It'd also be nice if this was also sorted alphabetically, but I'm not that fussy.) Tags: Documentation and Manuals.Video Games Results: Documentation and Manuals Tags: Fanfiction.Crossover, Fanfiction.Half-Life & Portal, Fanfiction.Mass Effect Results: Fanfiction Tags: Fanfiction.Crossover, Fiction.Animals.Cats Results: Fanfiction, Fiction, Animals, Cats My own solution to this is pretty much this, which works but is a bit clumsy: Code:
{tags:'list_difference(re($, '\.', ', '), 'Video Games, Strategy Guides, Crossover, Half-Life & Portal, Mass Effect', ',')'} Last edited by ownedbycats; 12-21-2020 at 06:58 AM. |
![]() |
![]() |
![]() |
#7 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I think you want a new item list consisting of
Code:
program: g = field('#genre'); stripped_hierarchies = list_re_group(g, ',', '.', '^(Fanfiction|Documentation and Manuals)($|\..*$)', '{$}', ''); split_hierarchies = re(stripped_hierarchies, '\.', ','); cleaned = list_union('', split_hierarchies, ','); sorted = list_sort(cleaned, 0, ',') EDIT: added list_sort to the template. Last edited by chaley; 12-21-2020 at 12:26 PM. Reason: Edit: added list_sort |
![]() |
![]() |
![]() |
#8 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
That did it! Thank you.
![]() |
![]() |
![]() |
![]() |
#9 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Question: There's a number of specific tags I'd like to remove, but not their children. (e.g. Fiction.Cultures & Regions.Canada or Fiction.Social Issues.Prejudice & Racism - in these cases "Cultures & Regions" and "Social Issues" are just organizational tags and I don't need them to appear in the lists.)
Is this along the right lines? No errors, but it didn't actually remove the tags. Code:
program: g = field('tags'); stripped_hierarchies = list_re_group(g, ',', '.', '^(Fanfiction|Documentation and Manuals)($|\..*$)', '(Cultures & Regions|Social Issues)', '{$}', ''); split_hierarchies = re(stripped_hierarchies, '\.', ','); cleaned = list_union('', split_hierarchies, ','); sorted = list_sort(cleaned, 0, ',') Last edited by ownedbycats; 12-27-2020 at 02:29 PM. |
![]() |
![]() |
![]() |
#10 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Again, I am not sure what exactly you want to do. If you want to remove "Fiction.Cultures & Regions" and "Fiction.Social Issues" prefixes but leave their children then try this:
Code:
program: g = field('#genre'); stripped_hierarchies = list_re_group(g, ',', '.', '^(Fanfiction|Documentation and Manuals|Fiction\.Cultures & Regions|Fiction\.Social Issues)($|\..*$)', '{$}', ''); split_hierarchies = re(stripped_hierarchies, '\.', ','); cleaned = list_union('', split_hierarchies, ','); sorted = list_sort(cleaned, 0, ',') |
![]() |
![]() |
![]() |
#11 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Here's what I wanted to do:
Tags: Fiction.Cultures & Regions.Canada, Fiction.Social issues.Prejudice and Racism Results: Fiction, Canada, Prejudice and Racism Unfortunately the template instead gave me Fiction, Cultures & Regions, Social Issues. Last edited by ownedbycats; 12-27-2020 at 05:14 PM. |
![]() |
![]() |
![]() |
#12 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The above notwithstanding, this might do what you want. Code:
program: g = field('#genre'); stripped_hierarchies = list_re_group(g, ',', '.', '^(Fanfiction|Documentation and Manuals)($|\..*$)', '{$}', ''); split_hierarchies = re(stripped_hierarchies, '\.', ','); split_hierarchies = list_difference( split_hierarchies, 'Cultures & Regions, Social Issues', ','); cleaned = list_union('', split_hierarchies, ','); sorted = list_sort(cleaned, 0, ',') Last edited by chaley; 12-27-2020 at 05:33 PM. |
|
![]() |
![]() |
![]() |
#13 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
That works. Thank you.
![]() The "Cultures & Regions" and "Social issues" tags are mostly just to group together tags of similar themes for easier navigation in the browser. No actual books in the tag, only its children. The composite column is generally to make the Book Details a little tidier-looking, but I also found that it'll also let me view all the related books on that topic (e.g. clicking on "Canada" shows books from Fiction.Cultures & Regions.Canada, Nonfiction.History.Canada, and Nonfiction.Travel Guides.Canada) without having to flatten all the tags. Last edited by ownedbycats; 12-27-2020 at 05:49 PM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Dragging a book into an expanded Hierarchy level collapse other expanded levels | ChrisMillward | Calibre | 3 | 07-04-2020 06:02 AM |
Hierarchy columns | mezme | Calibre | 7 | 03-07-2016 01:10 PM |
Hierarchy problem | Clovis99 | Library Management | 12 | 12-04-2013 06:53 AM |
Saved Searches - Using Hierarchy | nynaevelan | Library Management | 10 | 03-28-2011 10:45 PM |
Book Hierarchy | jjansen | Calibre | 4 | 04-10-2010 10:39 AM |