Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 11-01-2025, 11:42 AM   #1
Square
Junior Member
Square began at the beginning.
 
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?
Square is offline   Reply With Quote
Old 11-01-2025, 11:06 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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
kovidgoyal is offline   Reply With Quote
Advert
Old 11-02-2025, 11:30 AM   #3
Square
Junior Member
Square began at the beginning.
 
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?
Square is offline   Reply With Quote
Old 11-02-2025, 12:03 PM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
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:
Originally Posted by Square View Post
How to limit the search to books that are the LAST in any series?
Kovid created Calibre, so he should know.

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>
theducks is offline   Reply With Quote
Old 11-02-2025, 12:06 PM   #5
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
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
theducks is offline   Reply With Quote
Advert
Old 11-02-2025, 03:52 PM   #6
bluefish2020
Junior Member
bluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead communitybluefish2020 has become a pillar of the MobileRead community
 
bluefish2020's Avatar
 
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
bluefish2020 is offline   Reply With Quote
Old 11-02-2025, 06:41 PM   #7
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
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
dunhill is offline   Reply With Quote
Reply


Forum Jump

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


All times are GMT -4. The time now is 02:12 PM.


MobileRead.com is a privately owned, operated and funded community.