A few small bugfixes, improvements:
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 24 Jan 2012 16:46:04 +0000 (11:46 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 24 Jan 2012 16:46:04 +0000 (11:46 -0500)
    * support for short_word_length argument in AutoSuggest.pm
        (corresponds to ShortWord option to ts_headline)
    * better commentary in AutoSuggest.pm
    * AutoSuggestStore now will use highlight_min, highlight_max, and
        short_word_length if provided
    * global flag-checking code for AutoSuggest enable/disable now
        working
    * fix an upgrade script bug (swapping label and name on the global flag)

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm
Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib_autosuggest.sql
Open-ILS/web/js/dojo/openils/AutoSuggestStore.js
Open-ILS/web/opac/skin/default/js/search_bar.js

index 21144ea..950a306 100644 (file)
@@ -49,6 +49,9 @@ my @_output_handler_types = sort {
 
 # 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;
 
@@ -58,8 +61,10 @@ sub prepare_for_tsquery {
     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;
 
@@ -70,10 +75,12 @@ sub prepare_headline_opts {
 
     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;
@@ -82,12 +89,14 @@ sub get_suggestions {
     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({
@@ -135,6 +144,10 @@ sub suggestions_to_json {
     });
 }
 
+# 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) = @_;
 
@@ -167,13 +180,14 @@ sub handler {
             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;
     }
index 96107b8..838512e 100644 (file)
@@ -2,7 +2,7 @@ BEGIN;
 
 SELECT evergreen.upgrade_deps_block_check('YYYY', :eg_version);
 
-INSERT INTO config.global_flag (label, name, enabled) VALUES (
+INSERT INTO config.global_flag (name, label, enabled) VALUES (
     'opac.use_autosuggest',
     'OPAC: Show auto-completing suggestions dialog under basic search box (put ''opac_visible'' into the value field to limit suggestions to OPAC-visible items)',
     FALSE
index 5d65291..5f24202 100644 (file)
@@ -25,6 +25,9 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         "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 */
@@ -85,6 +88,14 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
             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("&");
         },
 
index 9ab58b6..44ca3cc 100644 (file)
@@ -49,14 +49,13 @@ function updateSearchTypeSelector(id) {
 }
 
 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;