3
0
Fork 0

+ implement the suggestion in kiwix-serve

small_fixes
kelson42 13 years ago
parent a7397e73c3
commit bbc7644de0

@ -170,7 +170,7 @@ static int accessHandlerCallback(void *cls,
/* Get searcher and reader */
std::string humanReadableBookId = "";
if (!(urlStr.size() > 5 && urlStr.substr(0, 6) == "/skin/")) {
if (!strcmp(url, "/search")) {
if (!strcmp(url, "/search") || !strcmp(url, "/suggest")) {
const char* tmpGetValue = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "content");
humanReadableBookId = (tmpGetValue != NULL ? string(tmpGetValue) : "");
} else {
@ -188,8 +188,21 @@ static int accessHandlerCallback(void *cls,
readers.find(humanReadableBookId)->second : NULL;
pthread_mutex_unlock(&mapLock);
/* Get suggestions */
if (!strcmp(url, "/suggest") && reader != NULL) {
const char* term = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "term");
reader->searchSuggestions(term, 10);
string suggestion;
content = "[";
while (reader->getNextSuggestion(suggestion)) {
content += content == "[" ? "" : ",";
content += "{\"value\":\"" + suggestion + "\",\"id\":\"" + suggestion + "\"}";
}
content += "]\n";
}
/* Get static skin stuff */
if (urlStr.size() > 5 && urlStr.substr(0, 6) == "/skin/") {
else if (urlStr.size() > 5 && urlStr.substr(0, 6) == "/skin/") {
content = getResourceAsString(urlStr.substr(6));
}
@ -206,6 +219,10 @@ static int accessHandlerCallback(void *cls,
if (end != NULL)
endNumber = atoi(end);
if (pattern == NULL) {
pattern = "";
}
/* Get the results */
pthread_mutex_lock(&searcherLock);

@ -1,10 +1,42 @@
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#kiwixsearchbox" ).autocomplete({
source: "/suggest?content=__CONTENT__"
});
});
</script>
<span id="kiwixtoolbar" class="ui-widget-header ui-corner-all">
<button id="kiwixlibrary" onclick="window.location.href='/';">Library</button>
<button id="kiwixhome" onclick="window.location.href='/__CONTENT__/';">Home</button>
<form method="GET" action="/search" />
<input type="submit" id="kiwixsearch" value="Search" />
<input id="kiwixsearchbox" type="textbox" name="pattern" />
<input type="hidden" name="content" value="__CONTENT__" />
<input type="submit" id="kiwixsearch" value="Search" />
<input id="kiwixsearchbox" name="pattern"/>
</form>
</span>
<div style="display: block; height: 40px;"></div>

Loading…
Cancel
Save