Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash if we are searching on a zim file without fulltext index. #830

Merged
merged 2 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/suggestionlistworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,26 @@ void SuggestionListWorker::run()
urlList.append(url);
}
}
QUrlQuery query;

// Propose fulltext search
url.setPath("");
if (reader) {
// The host is used to determine the currentZimId
// The content query item is used to know in which zim search (as for kiwix-serve)
url.setHost(currentZimId + ".search");
query.addQueryItem("content", currentZimId);
if (reader->hasFulltextIndex()) {
// The host is used to determine the currentZimId
// The content query item is used to know in which zim search (as for kiwix-serve)
url.setHost(currentZimId + ".search");
QUrlQuery query;
query.addQueryItem("content", currentZimId);
query.addQueryItem("pattern", m_text);
url.setQuery(query);
suggestionList.append(m_text + " (" + gt("fulltext-search") + ")");
urlList.append(url);
}
} else {
// We do not allow multi zim search for now.
// We don't have a correct UI to select on which zim search,
// how to display results, ...
//url.setHost("library.search");
}
query.addQueryItem("pattern", m_text);
url.setQuery(query);
suggestionList.append(m_text + " (" + gt("fulltext-search") + ")");
urlList.append(url);
emit(searchFinished(suggestionList, urlList, m_token));
}
7 changes: 6 additions & 1 deletion src/urlschemehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ UrlSchemeHandler::handleSearchRequest(QWebEngineUrlRequestJob* request)
auto end = start + pageLength;

auto searcher = app->getLibrary()->getSearcher(bookId);
searcher->search(searchQuery, start, end);
try {
searcher->search(searchQuery, start, end);
} catch(std::runtime_error&) {
request->fail(QWebEngineUrlRequestJob::UrlInvalid);
return;
}

IdNameMapper nameMapper;
kiwix::SearchRenderer renderer(searcher.get(), &nameMapper);
Expand Down