# END package globals
+# Given a string such as a user might type into a search box, prepare
+# it for to_tsquery(). See
+# http://www.postgresql.org/docs/9.0/static/textsearch-controls.html
sub prepare_for_tsquery {
my ($str) = shift;
return join(" & ", split(/\s+/, $str));
}
+# The third argument to our stored procedure, metabib.suggest_browse_entries(),
+# is passed through directly to ts_headline() as the 'options' arugment.
sub prepare_headline_opts {
- my ($css_prefix, $highlight_min, $highlight_max) = @_;
+ my ($css_prefix, $highlight_min, $highlight_max, $short_word_length) = @_;
$css_prefix =~ s/[^\w]//g;
push @parts, "MinWords=$highlight_min" if $highlight_min > 0;
push @parts, "MaxWords=$highlight_max" if $highlight_max > 0;
+ push @parts, "ShortWord=$short_word_length" if defined $short_word_length;
return join(", ", @parts);
}
+# Get raw autosuggest data (rows returned from a stored procedure) from the DB.
sub get_suggestions {
my $editor = shift;
my $query = shift;
my $css_prefix = shift || 'oils_AS';
my $highlight_min = int(shift || 0);
my $highlight_max = int(shift || 0);
+ my $short_word_length = shift;
my $limit = int(shift || 10);
$limit = 10 unless $limit > 0;
my $headline_opts = prepare_headline_opts(
- $css_prefix, $highlight_min, $highlight_max
+ $css_prefix, $highlight_min, $highlight_max,
+ defined $short_word_length ? int($short_word_length) : undef
);
return $editor->json_query({
});
}
+# Given data and the Apache request object, this sub picks a sub from a
+# dispatch table based on the list of content-type encodings that the client
+# has indicated it will accept, and calls that sub, which will deliver
+# a response of appropriately encoded data.
sub output_handler {
my ($r, $data) = @_;
css_prefix
highlight_min
highlight_max
+ short_word_length
limit
)
);
if (not $suggestions) {
$r->log->error(
- "get_suggestsions() failed: " . $editor->die_event->{textcode}
+ "get_suggestions() failed: " . $editor->die_event->{textcode}
);
return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
}
"limit": 10,
"last_fetch": null,
"org_unit_getter": null,
+ "highlight_max": null,
+ "highlight_min": null,
+ "short_word_length": null,
"constructor": function(/* object */ args) {
dojo.mixin(this, args); /* XXX very sloppy */
if (typeof this.org_unit_getter == "function")
params.push("org_unit=" + this.org_unit_getter());
+ dojo.forEach(
+ ["highlight_max", "highlight_min", "short_word_length"],
+ dojo.hitch(this, function(arg) {
+ if (this[arg] != null)
+ params.push(arg + "=" + this[arg]);
+ })
+ );
+
return "/opac/extras/autosuggest?" + params.join("&");
},
}
function autoSuggestInit() {
+ var org_unit_getter = null;
var global_flag = fieldmapper.standardRequest(
- ["open-ils.fielder", "open-ils.fielder.cgf.atomic"], {
+ ["open-ils.fielder", "open-ils.fielder.cgf.atomic"], [{
"query": {"name": "opac.use_autosuggest"},
"fields": ["enabled", "value"]
- }
- );
-
- var org_unit_getter = null;
+ }]
+ ).shift(); /* XXX do we want to use caching here? a cookie? */
if (!global_flag || !openils.Util.isTrue(global_flag.enabled)) {
return;