diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 5bb818f5e8..56455f3b27 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -982,6 +982,9 @@ class DB: def fts_unindex(self, book_id, fmt=None): self.fts.unindex(book_id, fmt=fmt) + def reindex_fts_book(self, book_id, *fmts): + return self.fts.dirty_book(book_id, *fmts) + def fts_search(self, fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, restrict_to_book_ids, return_text, ): diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index df6cb66958..bd9319ef25 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -551,6 +551,15 @@ class Cache: self._update_fts_indexing_numbers() return ans + @write_api + def reindex_fts_book(self, book_id, *fmts): + if not self.is_fts_enabled(): + return + if not fmts: + fmts = self._formats(book_id) + self.backend.reindex_fts_book(book_id, *fmts) + self._queue_next_fts_job() + @api def reindex_fts(self): if not self.is_fts_enabled(): diff --git a/src/calibre/db/fts/connect.py b/src/calibre/db/fts/connect.py index 5a65ec30e6..68f1fc3d18 100644 --- a/src/calibre/db/fts/connect.py +++ b/src/calibre/db/fts/connect.py @@ -85,6 +85,11 @@ class FTS: conn = self.get_connection() conn.execute('DELETE FROM fts_db.dirtied_formats WHERE book=? AND format=?', (book_id, fmt.upper())) + def dirty_book(self, book_id, *fmts): + conn = self.get_connection() + for fmt in fmts: + conn.execute('INSERT OR IGNORE INTO fts_db.dirtied_formats (book, format) VALUES (?, ?)', (book_id, fmt.upper())) + def unindex(self, book_id, fmt=None): conn = self.get_connection() if fmt is None: diff --git a/src/calibre/db/tests/fts_api.py b/src/calibre/db/tests/fts_api.py index 2a0138f1d5..64bd2d1bcb 100644 --- a/src/calibre/db/tests/fts_api.py +++ b/src/calibre/db/tests/fts_api.py @@ -184,6 +184,9 @@ class FTSAPITest(BaseTest): self.ae(j, fts.get_next_fts_job()) fts.remove_dirty(*j) self.assertNotEqual(j, fts.get_next_fts_job()) + self.assertFalse(fts.all_currently_dirty()) + cache.reindex_fts_book(2) + self.ae(fts.all_currently_dirty(), [(2, 'ADDED')]) def test_fts_to_text(self): from calibre.ebooks.oeb.polish.parsing import parse