removed redirect to articles in search

This commit is contained in:
Manan Jethwani 2021-04-20 01:36:54 +05:30
parent 11db5dec4e
commit 965b9622c2
2 changed files with 0 additions and 32 deletions

View File

@ -497,30 +497,6 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
reader = mp_library->getReaderById(bookId); reader = mp_library->getReaderById(bookId);
} catch (const std::out_of_range&) {} } catch (const std::out_of_range&) {}
/* Try first to load directly the article */
if (reader != nullptr && !patternString.empty()) {
std::string patternCorrespondingUrl;
auto variants = reader->getTitleVariants(patternString);
auto variantsItr = variants.begin();
while (patternCorrespondingUrl.empty() && variantsItr != variants.end()) {
try {
auto entry = reader->getEntryFromTitle(*variantsItr);
entry = entry.getFinalEntry();
patternCorrespondingUrl = entry.getPath();
break;
} catch(kiwix::NoEntry& e) {
variantsItr++;
}
}
/* If article found then redirect directly to it */
if (!patternCorrespondingUrl.empty()) {
auto redirectUrl = m_root + "/" + bookName + "/" + patternCorrespondingUrl;
return Response::build_redirect(*this, redirectUrl);
}
}
/* Make the search */ /* Make the search */
if ( (!reader && !bookName.empty()) if ( (!reader && !bookName.empty())
|| (patternString.empty() && ! has_geo_query) ) { || (patternString.empty() && ! has_geo_query) ) {

View File

@ -269,14 +269,6 @@ TEST_F(ServerTest, 404)
EXPECT_EQ(404, zfs1_->GET(url)->status) << "url: " << url; EXPECT_EQ(404, zfs1_->GET(url)->status) << "url: " << url;
} }
TEST_F(ServerTest, SuccessfulSearchForAnArticleTitleRedirectsToTheArticle)
{
auto g = zfs1_->GET("/search?content=zimfile&pattern=ray%20charles" );
ASSERT_EQ(302, g->status);
ASSERT_TRUE(g->has_header("Location"));
ASSERT_EQ("/zimfile/A/Ray_Charles", g->get_header_value("Location"));
}
TEST_F(ServerTest, RandomPageRedirectsToAnExistingArticle) TEST_F(ServerTest, RandomPageRedirectsToAnExistingArticle)
{ {
auto g = zfs1_->GET("/random?content=zimfile"); auto g = zfs1_->GET("/random?content=zimfile");