fun lowercase(s) {
implode(for (c <- explode(s)) [toLower(c)])
}
fun suggest(pre) client {
domReplaceChildren(
format(completions(lowercase(pre))),
getNodeById("suggestions")
)
}
fun format(words) {
for (w <- words)
{stringToXml(w.word)}
{stringToXml(w.type)}:
{stringToXml(w.meaning)}
}
fun completions(pre) server {
var wordlist = table "wordlist" with (
word : String,
type : String,
meaning : String
) from (database "dictionary");
debug("pre: " ^^ pre);
if (pre == "") []
else {
query [10] {
for (w <-- wordlist)
where (w.word =~ /^{pre}.*/)
orderby (w.word)
[w]
}
}
}
fun main() {
page