|
|
@ -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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|