Merge pull request #744 from kiwix/fullsearch_text_unavailable_error

This commit is contained in:
Matthieu Gautier 2022-04-06 15:14:18 +02:00 committed by GitHub
commit a17258fcc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 28 deletions

View File

@ -447,6 +447,11 @@ std::string noSuchBookErrorMsg(const std::string& bookName)
return "No such book: " + bookName; return "No such book: " + bookName;
} }
std::string noSearchResultsMsg()
{
return "The fulltext search engine is not available for this content.";
}
} // unnamed namespace } // unnamed namespace
std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& request) std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& request)
@ -591,12 +596,12 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
} catch(std::runtime_error& e) { } catch(std::runtime_error& e) {
// Searcher->search will throw a runtime error if there is no valid xapian database to do the search. // Searcher->search will throw a runtime error if there is no valid xapian database to do the search.
// (in case of zim file not containing a index) // (in case of zim file not containing a index)
auto data = get_default_data(); return HTTPErrorHtmlResponse(*this, request, MHD_HTTP_NOT_FOUND,
data.set("pattern", encodeDiples(searchInfo.pattern)); "Fulltext search unavailable",
auto response = ContentResponse::build(*this, RESOURCE::templates::no_search_result_html, data, "text/html; charset=utf-8"); "Not Found",
response->set_code(MHD_HTTP_NOT_FOUND); m_root + "/skin/search_results.css")
response->set_taskbar(searchInfo.bookName, archive.get()); + noSearchResultsMsg()
return std::move(response); + TaskbarInfo(searchInfo.bookName, archive.get());
} }

View File

@ -101,7 +101,8 @@ HTTPErrorHtmlResponse::HTTPErrorHtmlResponse(const InternalServer& server,
const RequestContext& request, const RequestContext& request,
int httpStatusCode, int httpStatusCode,
const std::string& pageTitleMsg, const std::string& pageTitleMsg,
const std::string& headingMsg) const std::string& headingMsg,
const std::string& cssUrl)
: ContentResponseBlueprint(&server, : ContentResponseBlueprint(&server,
&request, &request,
httpStatusCode, httpStatusCode,
@ -110,6 +111,7 @@ HTTPErrorHtmlResponse::HTTPErrorHtmlResponse(const InternalServer& server,
{ {
kainjow::mustache::list emptyList; kainjow::mustache::list emptyList;
this->m_data = kainjow::mustache::object{ this->m_data = kainjow::mustache::object{
{"CSS_URL", onlyAsNonEmptyMustacheValue(cssUrl) },
{"PAGE_TITLE", pageTitleMsg}, {"PAGE_TITLE", pageTitleMsg},
{"PAGE_HEADING", headingMsg}, {"PAGE_HEADING", headingMsg},
{"details", emptyList} {"details", emptyList}

View File

@ -184,7 +184,8 @@ struct HTTPErrorHtmlResponse : ContentResponseBlueprint
const RequestContext& request, const RequestContext& request,
int httpStatusCode, int httpStatusCode,
const std::string& pageTitleMsg, const std::string& pageTitleMsg,
const std::string& headingMsg); const std::string& headingMsg,
const std::string& cssUrl = "");
using ContentResponseBlueprint::operator+; using ContentResponseBlueprint::operator+;
HTTPErrorHtmlResponse& operator+(const std::string& msg); HTTPErrorHtmlResponse& operator+(const std::string& msg);

View File

@ -34,7 +34,6 @@ skin/fonts/Roboto.ttf
skin/block_external.js skin/block_external.js
skin/search_results.css skin/search_results.css
templates/search_result.html templates/search_result.html
templates/no_search_result.html
templates/error.html templates/error.html
templates/index.html templates/index.html
templates/suggestion.json templates/suggestion.json

View File

@ -18,7 +18,7 @@ a:hover {
text-decoration: underline text-decoration: underline
} }
.header { h1 {
font-size: 120%; font-size: 120%;
} }

View File

@ -3,6 +3,9 @@
<head> <head>
<meta content="text/html;charset=UTF-8" http-equiv="content-type" /> <meta content="text/html;charset=UTF-8" http-equiv="content-type" />
<title>{{PAGE_TITLE}}</title> <title>{{PAGE_TITLE}}</title>
{{#CSS_URL}}
<link type="text/css" href="{{{CSS_URL}}}" rel="Stylesheet" />
{{/CSS_URL}}
</head> </head>
<body> <body>
<h1>{{PAGE_HEADING}}</h1> <h1>{{PAGE_HEADING}}</h1>

View File

@ -1,15 +0,0 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
<title>Fulltext search unavailable</title>
<link type="text/css" href="{{root}}/skin/search_results.css" rel="Stylesheet" />
</head>
<body>
<div class="header">Not found</div>
<p>
There is no article with the title <b> "{{pattern}}"</b>
and the fulltext search engine is not available for this content.
</p>
</body>
</html>

View File

@ -430,7 +430,8 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const
R"FRAG(</title> R"FRAG(</title>
)FRAG", )FRAG",
R"FRAG( <link type="root" href="/ROOT"><link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" /> R"FRAG(
<link type="root" href="/ROOT"><link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
<link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" /> <link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
<link type="text/css" href="/ROOT/skin/taskbar.css" rel="Stylesheet" /> <link type="text/css" href="/ROOT/skin/taskbar.css" rel="Stylesheet" />
<script type="text/javascript" src="/ROOT/skin/jquery-ui/external/jquery/jquery.js" defer></script> <script type="text/javascript" src="/ROOT/skin/jquery-ui/external/jquery/jquery.js" defer></script>
@ -497,8 +498,7 @@ std::string TestContentIn404HtmlResponse::pageCssLink() const
return R"( <link type="text/css" href=")" return R"( <link type="text/css" href=")"
+ expectedCssUrl + expectedCssUrl
+ R"(" rel="Stylesheet" /> + R"(" rel="Stylesheet" />)";
)";
} }
std::string TestContentIn404HtmlResponse::hiddenBookNameInput() const std::string TestContentIn404HtmlResponse::hiddenBookNameInput() const
@ -686,6 +686,18 @@ TEST_F(ServerTest, 404WithBodyTesting)
Cannot find content entry invalid-article Cannot find content entry invalid-article
</p> </p>
)" }, )" },
{ /* url */ "/ROOT/search?content=poor&pattern=whatever",
expected_page_title=="Fulltext search unavailable" &&
expected_css_url=="/ROOT/skin/search_results.css" &&
book_name=="poor" &&
book_title=="poor" &&
expected_body==R"(
<h1>Not Found</h1>
<p>
The fulltext search engine is not available for this content.
</p>
)" },
}; };
for ( const auto& t : testData ) { for ( const auto& t : testData ) {
@ -769,6 +781,7 @@ TEST_F(ServerTest, 500)
<head> <head>
<meta content="text/html;charset=UTF-8" http-equiv="content-type" /> <meta content="text/html;charset=UTF-8" http-equiv="content-type" />
<title>Internal Server Error</title> <title>Internal Server Error</title>
</head> </head>
<body> <body>
<h1>Internal Server Error</h1> <h1>Internal Server Error</h1>