|
JavaScript::Autocomplete::Backend - Google Suggest-compatible autocompletion backend |
JavaScript::Autocomplete::Backend - Google Suggest-compatible autocompletion backend
package MyAutocompleter;
use base qw(JavaScript::Autocomplete::Backend);
my @NAMES = qw(alice bob charlie);
sub expand {
my ($self, $query) = @_;
# do something to expand the query
my $re = qr/^\Q$query\E/i;
my @names = grep /$re/, @NAMES;
(lc $query, \@names, [], [""]);
}
MyAutocompleter->run;
This is a base class for implementing an autocompletion server with the same protocol used by Google Suggest ( http://www.google.com/webhp?complete=1&hl=en ). It is basically a CGI script that takes a word to be completed as the ``qu'' parameter and returns a specially concoted JavaScript statement. For more efficiency it should be possible to turn it into a mod_perl handler; that is left as an exercise for the reader.
The front-end JavaScript code is discussed in http://serversideguy.blogspot.com/2004/12/google-suggest-dissected.html .
This module is used by creating a subclass, which should override the
expand method, which takes care of searching for the autocompletion results.
run(%args)new(%args)cgi, which should provide a the CGI manpage or CGI-compatible object. If
none is provided, a new the CGI manpage object is created by default.
param($name)header(%args)expand($query)as_array(\@arr)
print $obj->as_array(["a", "b", "c"]);
# prints 'new Array("a", "b", "c")'
js
CGI parameter is not true.
http://www.google.com/webhp?complete=1&hl=en
http://serversideguy.blogspot.com/2004/12/google-suggest-dissected.html
0.10
Ivan Tubert-Brohman <itub@cpan.org>
Copyright (c) 2004 Ivan Tubert-Brohman. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The original JavaScript frontend code is Copyright (c) 2004 Google, Inc. Use it at your own risk or write or find a free version.
|
JavaScript::Autocomplete::Backend - Google Suggest-compatible autocompletion backend |