+ simplifaction of the code = cleaning

pull/9/head
kelson42 12 years ago
parent fad1149ba5
commit 8b34459e4b

@ -284,46 +284,24 @@ static int accessHandlerCallback(void *cls,
if (pattern == NULL) if (pattern == NULL)
pattern = ""; pattern = "";
std::string patternString = kiwix::urlDecode(string(pattern)); std::string patternString = kiwix::urlDecode(string(pattern));
/* Try first to load directly the article if exactly matching the pattern */
std::string patternCorrespondingUrl; 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 */ /* Try first to load directly the article */
if (!found) { if (reader != NULL) {
patternString = kiwix::ucFirst(patternString); std::vector<std::string> variants = reader->getTitleVariants(patternString);
reader->getPageUrlFromTitle(patternString, patternCorrespondingUrl); std::vector<std::string>::iterator variantsItr = variants.begin();
found = !patternCorrespondingUrl.empty();
}
/* Try with first letter lowercase */
if (!found) {
patternString = kiwix::lcFirst(patternString);
reader->getPageUrlFromTitle(patternString, patternCorrespondingUrl);
found = !patternCorrespondingUrl.empty();
}
/* Try with title words */ pthread_mutex_lock(&readerLock);
if (!found) { while (patternCorrespondingUrl.empty() && variantsItr != variants.end()) {
patternString = kiwix::toTitle(patternString); reader->getPageUrlFromTitle(*variantsItr, patternCorrespondingUrl);
reader->getPageUrlFromTitle(patternString, patternCorrespondingUrl); variantsItr++;
found = !patternCorrespondingUrl.empty();
} }
pthread_mutex_unlock(&readerLock); pthread_mutex_unlock(&readerLock);
/* If article found then redirect directly to it */ /* If article found then redirect directly to it */
if (!patternCorrespondingUrl.empty()) { if (!patternCorrespondingUrl.empty()) {
httpRedirection="/" + humanReadableBookId + "/" + patternCorrespondingUrl; httpRedirection="/" + humanReadableBookId + "/" + patternCorrespondingUrl;
} }
} }
/* Make the search */ /* Make the search */

Loading…
Cancel
Save