mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-29 15:21:35 -04:00
+ if not suggestions try ucFirst() and lcFirst() on the pattern
This commit is contained in:
parent
717b7a902a
commit
52f7b38a46
@ -211,23 +211,36 @@ static int accessHandlerCallback(void *cls,
|
|||||||
|
|
||||||
/* Get suggestions */
|
/* Get suggestions */
|
||||||
if (!strcmp(url, "/suggest") && reader != NULL) {
|
if (!strcmp(url, "/suggest") && reader != NULL) {
|
||||||
const char* term = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "term");
|
unsigned int maxSuggestionCount = 10;
|
||||||
if (term == NULL) {
|
unsigned int suggestionCount = 0;
|
||||||
term = "";
|
std::string suggestion;
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Get the suggestion pattern from the HTTP request */
|
||||||
|
const char* cTerm = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "term");
|
||||||
|
std::string term = cTerm == NULL ? "" : cTerm;
|
||||||
if (isVerbose()) {
|
if (isVerbose()) {
|
||||||
std::cout << "Searching suggestions for: \"" << term << "\"" << endl;
|
std::cout << "Searching suggestions for: \"" << term << "\"" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader->searchSuggestions(term, 10);
|
/* Get the suggestions */
|
||||||
string suggestion;
|
|
||||||
content = "[";
|
content = "[";
|
||||||
|
reader->searchSuggestions(term, maxSuggestionCount);
|
||||||
while (reader->getNextSuggestion(suggestion)) {
|
while (reader->getNextSuggestion(suggestion)) {
|
||||||
content += (content == "[" ? "" : ",");
|
content += (content == "[" ? "" : ",");
|
||||||
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
|
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
|
||||||
|
suggestionCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Try to get further suggestions with ucFirst(pattern )if maxSuggestionCount is not reached */
|
||||||
|
term = kiwix::ucFirst(term);
|
||||||
|
reader->searchSuggestions(term, maxSuggestionCount);
|
||||||
|
while (reader->getNextSuggestion(suggestion)) {
|
||||||
content += (content == "[" ? "" : ",");
|
content += (content == "[" ? "" : ",");
|
||||||
|
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
|
||||||
|
suggestionCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
content += (suggestionCount == 0 ? "" : ",");
|
||||||
content += "{\"value\":\"" + std::string(term) + " \", \"label\":\"containing '" + std::string(term) + "'...\"}]";
|
content += "{\"value\":\"" + std::string(term) + " \", \"label\":\"containing '" + std::string(term) + "'...\"}]";
|
||||||
mimeType = "text/x-json; charset=utf-8";
|
mimeType = "text/x-json; charset=utf-8";
|
||||||
}
|
}
|
||||||
@ -251,7 +264,6 @@ static int accessHandlerCallback(void *cls,
|
|||||||
reader->getPageUrlFromTitle(pattern, patternCorrespondingUrl);
|
reader->getPageUrlFromTitle(pattern, patternCorrespondingUrl);
|
||||||
pthread_mutex_unlock(&readerLock);
|
pthread_mutex_unlock(&readerLock);
|
||||||
if (!patternCorrespondingUrl.empty()) {
|
if (!patternCorrespondingUrl.empty()) {
|
||||||
std::cout << "Search url:" << patternCorrespondingUrl << std::endl;
|
|
||||||
httpRedirection="/" + humanReadableBookId + "/" + patternCorrespondingUrl;
|
httpRedirection="/" + humanReadableBookId + "/" + patternCorrespondingUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user