Content server: Allow disabling full text search via the web interface. Fixes #2020237 [[content server] Disable fulltext search activation via web interface](https://bugs.launchpad.net/calibre/+bug/2020237)

This commit is contained in:
Kovid Goyal 2023-05-23 17:55:51 +05:30
parent 9bfcd7c3bd
commit 924ba7adfe
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 40 additions and 2 deletions

View File

@ -54,6 +54,14 @@ def fts_search(ctx, rd):
return ans
@endpoint('/fts/disable', needs_db_write=True)
def fts_disable(ctx, rd):
db = get_library_data(ctx, rd)[0]
if db.is_fts_enabled():
db.enable_fts(enabled=False)
return ''
@endpoint('/fts/reindex', needs_db_write=True, methods=('POST',))
def fts_reindex(ctx, rd):
db = get_library_data(ctx, rd)[0]

View File

@ -8,7 +8,7 @@ from ajax import ajax, ajax_send
from book_list.cover_grid import THUMBNAIL_MAX_HEIGHT, THUMBNAIL_MAX_WIDTH
from book_list.globals import get_current_query, get_session_data
from book_list.library_data import current_library_id, download_url
from book_list.router import back, open_book_url, push_state
from book_list.router import back, home, open_book_url, push_state
from book_list.top_bar import create_top_bar
from book_list.ui import set_panel_handler
from book_list.views import create_image
@ -34,7 +34,9 @@ add_extra_css(def():
)
def component(name):
return document.getElementById(overall_container_id)?.querySelector(f'[data-component="{name}"]')
c = document.getElementById(overall_container_id)
if c:
return c.querySelector(f'[data-component="{name}"]')
def showing_search_panel():
@ -157,6 +159,8 @@ def clear_to_help():
container.appendChild(E.div(
style='margin-top: 1ex',
E.a(_('Re-index all books in this library'), class_='blue-link', href='javascript:void(0)', onclick=reindex_all),
E.span('\xa0\xa0'),
E.a(_('Disable full text search'), class_='blue-link', href='javascript:void(0)', onclick=disable_fts),
))
container = container.firstChild
fts_url = 'https://www.sqlite.org/fts5.html#full_text_query_syntax'
@ -245,6 +249,32 @@ def reindex_all():
)
def disable_fts_backend():
def on_response(end_type, xhr, ev):
if end_type is 'abort' or not showing_search_panel():
return
if end_type is not 'load':
if xhr.status is 403:
return error_dialog(_('Permission denied'), _(
'You do not have permission to disable FTS. Only logged in users with write permission are allowed to disable FTS.'), xhr.error_html)
return error_dialog(_('Disabling FTS failed'), _('Disabling FTS failed. Click "Show details" for more information.'), xhr.error_html)
info_dialog(_('Full text searching disabled'), _('Full text searching for this library has been disabled. In the future the entire library will have to be re-indexed when re-enabling full text searching.'), on_close=def():
window.setTimeout(home)
)
ajax(f'fts/disable', on_response, bypass_cache=True).send()
def disable_fts():
question_dialog(_('Are you sure?'), _('Disabling full text search means that in the future the entire library will have to be re-indexed to use full text search. Are you sure you want to proceed?'),
def (yes):
if yes:
disable_fts_backend()
)
def book_result_tile_clicked(ev):
result_tile = ev.currentTarget
bid = int(result_tile.dataset.bookId)