Allow enabling indexing from the server

This commit is contained in:
Kovid Goyal 2022-12-12 21:37:40 +05:30
parent 7de0514d30
commit 2b5b422301
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 41 additions and 4 deletions

View File

@ -4,7 +4,7 @@
__license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
from polyglot import http_client
import http.client as http_client
class JobQueueFull(Exception):

View File

@ -72,6 +72,20 @@ def fts_reindex(ctx, rd):
return ''
@endpoint('/fts/indexing', needs_db_write=True, methods=('POST',))
def fts_indexing(ctx, rd):
data = rd.request_body_file.read()
try:
enable = json.loads(data)
except Exception:
raise HTTPBadRequest('Invalid boolean')
if not isinstance(enable, bool):
raise HTTPBadRequest('Invalid boolean')
db = get_library_data(ctx, rd)[0]
db.enable_fts(enable)
return ''
@endpoint('/fts/snippets/{book_ids}', postprocess=json)
def fts_snippets(ctx, rd, book_ids):
'''

View File

@ -8,9 +8,10 @@ from http.client import (responses, HTTPConnection, HTTPSConnection,
NOT_FOUND, NOT_IMPLEMENTED, NOT_MODIFIED, OK, PARTIAL_CONTENT,
PRECONDITION_FAILED, REQUEST_ENTITY_TOO_LARGE, REQUEST_URI_TOO_LONG,
REQUESTED_RANGE_NOT_SATISFIABLE, REQUEST_TIMEOUT, SEE_OTHER,
SERVICE_UNAVAILABLE, UNAUTHORIZED, _CS_IDLE, _CS_REQ_SENT)
SERVICE_UNAVAILABLE, UNAUTHORIZED, _CS_IDLE, _CS_REQ_SENT, PRECONDITION_REQUIRED, UNPROCESSABLE_ENTITY)
if False:
responses, HTTPConnection, HTTPSConnection, BAD_REQUEST, FOUND, FORBIDDEN, HTTP_VERSION_NOT_SUPPORTED, INTERNAL_SERVER_ERROR, METHOD_NOT_ALLOWED
MOVED_PERMANENTLY, NOT_FOUND, NOT_IMPLEMENTED, NOT_MODIFIED, OK, PARTIAL_CONTENT, PRECONDITION_FAILED, REQUEST_ENTITY_TOO_LARGE, REQUEST_URI_TOO_LONG
REQUESTED_RANGE_NOT_SATISFIABLE, REQUEST_TIMEOUT, SEE_OTHER, SERVICE_UNAVAILABLE, UNAUTHORIZED, _CS_IDLE, _CS_REQ_SENT
PRECONDITION_REQUIRED, UNPROCESSABLE_ENTITY

View File

@ -53,13 +53,35 @@ def make_new_fts_query(q):
xhr.send()
def enable_indexing():
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 enable indexing. Only logged in users with write permission are allowed.'), xhr.error_html)
return error_dialog(_('Failed to enable indexing'), _('Enabling indexing failed. Click "Show details" for more information.'), xhr.error_html)
info_dialog(_('Indexing enabled'), _('Indexing of this library has been enabled. Depending on library size it can take a long time to index all books.'))
ajax_send(f'fts/indexing', True, on_response)
def report_fts_not_enabled():
clear_to_waiting_for_results(_('No matches found'))
question_dialog(_('Full text searching disabled'), _(
'Full text search indexing has not been enabled for this library. Once enabled, indexing'
' will take some time to complete after which searching will work. Enable indexing?'),
def (yes):
if yes:
enable_indexing()
)
def on_initial_fts_fetched(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 428:
# TODO: Implement FTS not enabled
pass
return report_fts_not_enabled()
return error_dialog(_('Failed to search'), _('The search failed. Click "Show details" for more information.'), xhr.error_html)
try:
results = JSON.parse(xhr.responseText)