Skip to content

Commit

Permalink
Merge pull request #1086 from kiwix/handling_of_corrupted_xapian_db
Browse files Browse the repository at this point in the history
Handling of corrupted Xapian DB during search
  • Loading branch information
kelson42 authored Apr 12, 2024
2 parents 20f32d0 + 79bf305 commit cce7de8
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/urlschemehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ class IdNameMapper : public kiwix::NameMapper {
};


namespace
{

struct SearchResultsWithEstimatedMatchCount
{
std::shared_ptr<zim::SearchResultSet> results;
int estimatedMatchCount = 0;
};

SearchResultsWithEstimatedMatchCount getSearchResults(zim::Search& s, int start, int pageLength)
{
SearchResultsWithEstimatedMatchCount r;
r.estimatedMatchCount = s.getEstimatedMatches();
r.results = std::make_shared<zim::SearchResultSet>(s.getResults(start, pageLength));
return r;
}

} // unnamed namespace

void
UrlSchemeHandler::handleSearchRequest(QWebEngineUrlRequestJob* request)
{
Expand Down Expand Up @@ -131,10 +150,19 @@ UrlSchemeHandler::handleSearchRequest(QWebEngineUrlRequestJob* request)
request->fail(QWebEngineUrlRequestJob::UrlInvalid);
return;
}

SearchResultsWithEstimatedMatchCount searchResult;
try {
searchResult = getSearchResults(*search, start, pageLength);
} catch (...) {
request->fail(QWebEngineUrlRequestJob::RequestFailed);
return;
}

kiwix::SearchRenderer renderer(
search->getResults(start, pageLength),
*searchResult.results,
start,
search->getEstimatedMatches());
searchResult.estimatedMatchCount);
renderer.setSearchPattern(searchQuery);
renderer.setSearchBookQuery("content="+bookId.toStdString());
renderer.setProtocolPrefix("zim://");
Expand Down

0 comments on commit cce7de8

Please sign in to comment.