|
|
#1 |
|
want to learn what I want
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,682
Karma: 7908443
Join Date: Sep 2020
Device: none
|
Publisher count
Hi chaley,
This is mostly out of curiosity as I'm exploring the Template functions. I'm using the plugin Author Book Count to populate a column that stores the total number of books by each author while also providing an optional integer column that supports arithmetic search queries, named abc_numeric (I have a grouped search using 'abc' as lookup alias instead). So I sometimes do searches like Code:
not abc:=1 Code:
program: book_count('publisher',0);
Would you please advise a good way to create such a column? (I have already set the tweak allow_template_database_functions_in_composites to True.) Last edited by Comfy.n; 11-14-2024 at 07:27 AM. Reason: removed the # symbol |
|
|
|
|
|
#2 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
The correct query is
Code:
program: book_count('publisher:=' & $publisher & '"', 0)
This python template should be fast enough to use directly in a composite Code:
python:
def evaluate(book, context):
db = context.db.new_api
pub_id = db.field_ids_for('publisher', book.id)
if not pub_id:
return '0'
pub_id = pub_id[0]
counts = db.get_usage_count_by_id('publisher')
return str(counts[pub_id])
Last edited by chaley; 11-14-2024 at 09:59 AM. |
|
|
|
| Advert | |
|
|
|
|
#3 |
|
want to learn what I want
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,682
Karma: 7908443
Join Date: Sep 2020
Device: none
|
The python template is fast enough, thank you! I think I'm going to keep it for a while to see how it goes.
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Add page count, word count and reading time | ZodWallop | Kobo Reader | 4 | 08-12-2024 06:56 AM |
| Word Count and Page Count? | CrossReach | Library Management | 2 | 07-19-2018 06:44 PM |
| Count yourself in | wannabee | Lounge | 24 | 12-13-2011 09:54 AM |
| Count Me In | Teleguy1955 | Ectaco jetBook | 6 | 11-04-2010 04:27 PM |
| Too many to count....... | Stonecoldcrb | Sony Reader | 16 | 07-16-2007 04:45 PM |