mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
FTS API to re-index a book
This commit is contained in:
parent
4656e79cba
commit
cd91088c98
@ -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,
|
||||
):
|
||||
|
@ -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():
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user