12-01-2010, 10:58 PM | #1 |
Connoisseur
Posts: 63
Karma: 732
Join Date: Nov 2010
Device: Sony PRS-650
|
Feature request: How many authors?
Is there any way to count the number of items in a comma-separated field, such as the list of authors?
Basically, I'm after creating a custom column which contains a count of the number of authors for each book (to make life easier when it comes to manually cross-linking books into different collections on the kindle, since you ask). But for the life of me I can't see an {authors_count} or (authors:count()} or similar. |
12-02-2010, 01:16 AM | #2 |
Wizard
Posts: 4,552
Karma: 950151
Join Date: Nov 2008
Device: Sony PRS-950, iphone/ipad (Marvin/iBooks/QuickReader)
|
First time I can ever remember any asking about such a feature
You should raise the feature request by raising a ticket in the Calibre tracking system as forum messages for feature requests can get lost (and then forgotten) amongst the volume of messages posted. |
Advert | |
|
12-02-2010, 07:57 AM | #3 |
Connoisseur
Posts: 63
Karma: 732
Join Date: Nov 2010
Device: Sony PRS-650
|
|
12-02-2010, 08:29 AM | #4 |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Code submitted.
There is now a template function 'count'. It takes one argument, the character that separates the items in the list. Most lists use comma, but authors uses ampersand. Examples: tags: {tags:count(,)} authors: {authors:count(&)} a custom multiple field: {#mymult:count(,)} As another example, imagine that you have a custom field #genre that you use for hierarchical tagging. This would be a text (non-multiple) field containing things like Science:Biology:Plankton Fiction:Mystery:Crime:Police You can count these via {#genre:count(:)} Last edited by chaley; 12-02-2010 at 09:18 AM. |
12-02-2010, 09:13 AM | #5 |
Connoisseur
Posts: 63
Karma: 732
Join Date: Nov 2010
Device: Sony PRS-650
|
Wonderful. Thanks muchly for that - it'll come in very useful (especially the way you've implemented it).
Presumably this will show up in the next release? |
Advert | |
|
12-02-2010, 09:18 AM | #6 |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
12-02-2010, 11:32 AM | #7 |
Connoisseur
Posts: 63
Karma: 732
Join Date: Nov 2010
Device: Sony PRS-650
|
I'm sure it'll show up sometime ;-)
And thanks again for writing this. |
12-03-2010, 03:57 PM | #8 |
Connoisseur
Posts: 63
Karma: 732
Join Date: Nov 2010
Device: Sony PRS-650
|
And I see it's appeared in release 0.7.32.
One small issue. though, is that the "number" produced by count() seems to be treated as text, rather than an integer, for sorting purposes meaning that "{authors:count(&)}" can't be sorted numerically. This can be worked around by using a second custom column with "{#numauthors:0>2s}" but is there any way to have the whole thing done in a single field (i.e. so the output is "01","02,"03",etc) or to make the numbers in such a column be sorted as numbers, rather than as text? |
12-03-2010, 06:55 PM | #9 | |
Connoisseur
Posts: 63
Karma: 732
Join Date: Nov 2010
Device: Sony PRS-650
|
Quote:
|
|
12-04-2010, 04:05 AM | #10 | |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
{authors:0>2s:count(&)} As for specifying the sort type, that won't work in your case. Composite columns are always strings. |
|
12-04-2010, 05:19 AM | #11 | |
Connoisseur
Posts: 63
Karma: 732
Join Date: Nov 2010
Device: Sony PRS-650
|
Quote:
Sorting-wise, it's fine sorting by string so long as the string is zero-filled ;-) |
|
Tags |
count, feature request |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Feature request: | oilwood | Calibre | 5 | 11-08-2010 02:59 PM |
Feature Request | Partzz | Calibre | 6 | 09-09-2010 01:11 PM |
Feature Request? | Sydney's Mom | Calibre | 6 | 07-22-2010 12:32 PM |
Feature request | mrmikel | EPUBReader | 4 | 11-20-2009 11:49 AM |
Feature request | AprilHare | Calibre | 0 | 11-22-2008 05:42 AM |