From 8b34459e4bc751a81ce267032447b32d6e138bcf Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 27 Aug 2014 17:13:29 -0600 Subject: [PATCH] + simplifaction of the code = cleaning --- src/server/kiwix-serve.cpp | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 90494e3..5003e14 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -284,46 +284,24 @@ static int accessHandlerCallback(void *cls, if (pattern == NULL) pattern = ""; std::string patternString = kiwix::urlDecode(string(pattern)); - - /* Try first to load directly the article if exactly matching the pattern */ std::string patternCorrespondingUrl; - if (reader != NULL) { - - pthread_mutex_lock(&readerLock); - bool found = false; - - /* Try to see if there is an article with this title */ - reader->getPageUrlFromTitle(patternString, patternCorrespondingUrl); - found = !patternCorrespondingUrl.empty(); - /* Try with first letter uppercase */ - if (!found) { - patternString = kiwix::ucFirst(patternString); - reader->getPageUrlFromTitle(patternString, patternCorrespondingUrl); - found = !patternCorrespondingUrl.empty(); - } - - /* Try with first letter lowercase */ - if (!found) { - patternString = kiwix::lcFirst(patternString); - reader->getPageUrlFromTitle(patternString, patternCorrespondingUrl); - found = !patternCorrespondingUrl.empty(); - } + /* Try first to load directly the article */ + if (reader != NULL) { + std::vector variants = reader->getTitleVariants(patternString); + std::vector::iterator variantsItr = variants.begin(); - /* Try with title words */ - if (!found) { - patternString = kiwix::toTitle(patternString); - reader->getPageUrlFromTitle(patternString, patternCorrespondingUrl); - found = !patternCorrespondingUrl.empty(); + pthread_mutex_lock(&readerLock); + while (patternCorrespondingUrl.empty() && variantsItr != variants.end()) { + reader->getPageUrlFromTitle(*variantsItr, patternCorrespondingUrl); + variantsItr++; } - pthread_mutex_unlock(&readerLock); /* If article found then redirect directly to it */ if (!patternCorrespondingUrl.empty()) { httpRedirection="/" + humanReadableBookId + "/" + patternCorrespondingUrl; } - } /* Make the search */