|
|
#1 |
|
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Jun 2012
Device: Kindle 4 NT, Kindle Basic
|
How to search for last book in series?
How to search for the last book in a series?
I have a custom column where I mark if a series is still releasing new books, however over the years I've let this data get completely out of date. Is there a search expression to find the last book released in a series, so I can sort by date and mark the ones that are older than a few years as a completed series? |
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,609
Karma: 28549044
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Sort by the series column and use a search expression to restrict the results to books with a date older than X years ago
|
|
|
|
|
|
#3 |
|
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Jun 2012
Device: Kindle 4 NT, Kindle Basic
|
How to limit the search to books that are the LAST in any series?
|
|
|
|
|
|
#4 | |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,270
Karma: 61916422
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
You can't. Searches look at a Single record at a time. They have no concept of any other record. They simply add the found to the results view. You can sort on Series. That groups by order. Note there is no restriction on having multiples of the same Index. I use 0 for when there is no series placement ORDER specified (just a story within the series). In this case , there is no 'last' The closest PI that includes a report on series index is: Quality check: Check metadata: check series gaps <then view Log> |
|
|
|
|
|
|
#5 |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,270
Karma: 61916422
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Correction:
Quality check Plugins log does report Last Code:
Series: Desert Called Peace - Author: Tom Kratman - Last: #5
Missing#: 4
|
|
|
|
|
|
#6 |
|
Junior Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3
Karma: 15972
Join Date: Mar 2025
Device: kindle oasis
|
I do something close to that using an Action Chain similar to this code:
Code:
from calibre_plugins.action_chains.actions.base import ChainAction
class MarkLastBookInSeriesAction(ChainAction):
name = 'Mark Last Book In Series'
def run(self, gui, settings, chain):
db = gui.current_db
api = gui.current_db.new_api
book_ids = {}
series_names = api.all_field_names('series')
for series_name in series_names:
series_id = api.get_item_id('series', series_name)
books_in_series = api.books_for_field('series', series_id)
print(f"loaded {len(books_in_series)} books in series {series_name}")
book_id = self.last_book_in_series(api, books_in_series)
mark = 'last_book' if len(books_in_series) > 1 else 'only_book'
if book_id:
book_ids.update({book_id: mark})
db.set_marked_ids(book_ids)
# in practice setting the search likely belongs in its own link of the chain but this makes it less complicated to explain
gui.search.setEditText('marked:true')
gui.search.do_search()
def last_book_in_series(self, api, books_in_series):
indexes = api.all_field_for("series_index", books_in_series, None)
# primary works vs short stories...
# if 11.0 and 11.1 exist, do we really want the 11.1? probably not.
# also, ignore anything under 1. omnibus and prequels etc.
last_primary_work = None
last_minor_work = None
any_work = None
for book_id, i in sorted(indexes.items(), key=lambda kv: (kv[1], kv[0]), reverse=True):
if any_work is None:
any_work = book_id
if i < 1.0:
continue
if i.is_integer():
if last_primary_work is None:
last_primary_work = book_id # it would be safe to just return this now
else:
if last_minor_work is None:
last_minor_work = book_id
return last_primary_work or last_minor_work or any_work
|
|
|
|
|
|
#7 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 923
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
|
Once this topic has been discussed, please check this thread: https://www.mobileread.com/forums/sh...65&postcount=3
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Search For Series | anmatr | Library Management | 2 | 07-04-2025 09:20 AM |
| Search for series with a specific number of book | wladdy | Library Management | 3 | 07-03-2020 10:41 AM |
| search to show only lowest book in each series | YaronD | Library Management | 3 | 08-06-2019 06:45 PM |
| Search series with1 book | er0_senn1n | Library Management | 1 | 06-21-2017 09:48 AM |
| Google Book Search to search full-text books online | Bob Russell | Deals and Resources (No Self-Promotion or Affiliate Links) | 1 | 08-19-2006 01:13 PM |