FTS API to re-index a book

This commit is contained in:
Kovid Goyal 2022-07-13 08:08:53 +05:30
parent 4656e79cba
commit cd91088c98
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 20 additions and 0 deletions

View File

@ -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,
):

View File

@ -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():

View File

@ -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:

View File

@ -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