1) Make ts_rank_cd()'s normalization option controllable from UI level,
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 25 Jan 2012 18:03:43 +0000 (13:03 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 25 Jan 2012 18:03:43 +0000 (13:03 -0500)
2) add some comments here and there about such options that you can
control through AutoSuggestStore

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

index 30082fd..3e4d182 100644 (file)
@@ -90,6 +90,10 @@ sub get_suggestions {
     my $highlight_min = int(shift || 0);
     my $highlight_max = int(shift || 0);
     my $short_word_length = shift;
+
+    my $normalization = int(shift || 14);   # 14 is not totally arbitrary.
+    # See http://www.postgresql.org/docs/9.0/static/textsearch-controls.html#TEXTSEARCH-RANKING
+
     my $limit = int(shift || 10);
 
     $limit = 10 unless $limit > 0;
@@ -106,7 +110,8 @@ sub get_suggestions {
             $search_class,
             $headline_opts,
             $org_unit,
-            $limit
+            $limit,
+            $normalization
         ]
     });
 }
@@ -181,6 +186,7 @@ sub handler {
             highlight_min
             highlight_max
             short_word_length
+            normalization
             limit
         )
     );
index 150e18a..331e0c5 100644 (file)
@@ -1303,7 +1303,8 @@ CREATE OR REPLACE
         search_class    TEXT,   -- 'alias' or 'class' or 'class|field..', etc
         headline_opts   TEXT,   -- markup options for ts_headline()
         visibility_org  INTEGER,-- null if you don't want opac visibility test
-        query_limit     INTEGER -- use in LIMIT clause of interal query
+        query_limit     INTEGER,-- use in LIMIT clause of interal query
+        normalization   INTEGER -- argument to TS_RANK_CD()
     ) RETURNS TABLE (
         value                   TEXT,   -- plain
         match                   TEXT,   -- marked up
@@ -1380,17 +1381,20 @@ BEGIN
         cmc.bouyant AND _registered.field_class IS NOT NULL,
         _registered.field = cmf.id,
         cmf.weight,
-        TS_RANK_CD(mbe.index_vector, $1),
+        TS_RANK_CD(mbe.index_vector, $1, $6),
         cmc.bouyant
     FROM metabib.browse_entry_def_map mbedm
     JOIN metabib.browse_entry mbe ON (mbe.id = mbedm.entry)
     JOIN config.metabib_field cmf ON (cmf.id = mbedm.def)
     JOIN config.metabib_class cmc ON (cmf.field_class = cmc.name)
-    '  || search_class_join || opac_visibility_join || '
-    WHERE $1 @@ mbe.index_vector
+    '  || search_class_join || opac_visibility_join ||
+    WHERE $1 @@ mbe.index_vector
     ORDER BY 4 DESC, 5 DESC NULLS LAST, 6 DESC, 7 DESC, 8 DESC, 1 ASC
-    LIMIT $5
-    ' USING query, search_class, headline_opts, visibility_org, query_limit;
+    LIMIT $5'
+    USING
+        query, search_class, headline_opts,
+        visibility_org, query_limit, normalization
+        ;
 
     -- sort order:
     --  bouyant AND chosen class = match class
index e03f13c..9f8c663 100644 (file)
@@ -524,7 +524,8 @@ CREATE OR REPLACE
         search_class    TEXT,   -- 'alias' or 'class' or 'class|field..', etc
         headline_opts   TEXT,   -- markup options for ts_headline()
         visibility_org  INTEGER,-- null if you don't want opac visibility test
-        query_limit     INTEGER -- use in LIMIT clause of interal query
+        query_limit     INTEGER,-- use in LIMIT clause of interal query
+        normalization   INTEGER -- argument to TS_RANK_CD()
     ) RETURNS TABLE (
         value                   TEXT,   -- plain
         match                   TEXT,   -- marked up
@@ -601,17 +602,20 @@ BEGIN
         cmc.bouyant AND _registered.field_class IS NOT NULL,
         _registered.field = cmf.id,
         cmf.weight,
-        TS_RANK_CD(mbe.index_vector, $1),
+        TS_RANK_CD(mbe.index_vector, $1, $6),
         cmc.bouyant
     FROM metabib.browse_entry_def_map mbedm
     JOIN metabib.browse_entry mbe ON (mbe.id = mbedm.entry)
     JOIN config.metabib_field cmf ON (cmf.id = mbedm.def)
     JOIN config.metabib_class cmc ON (cmf.field_class = cmc.name)
-    '  || search_class_join || opac_visibility_join || '
-    WHERE $1 @@ mbe.index_vector
+    '  || search_class_join || opac_visibility_join ||
+    WHERE $1 @@ mbe.index_vector
     ORDER BY 4 DESC, 5 DESC NULLS LAST, 6 DESC, 7 DESC, 8 DESC, 1 ASC
-    LIMIT $5
-    ' USING query, search_class, headline_opts, visibility_org, query_limit;
+    LIMIT $5'
+    USING
+        query, search_class, headline_opts,
+        visibility_org, query_limit, normalization
+        ;
 
     -- sort order:
     --  bouyant AND chosen class = match class
index 5f24202..dab271f 100644 (file)
@@ -22,12 +22,20 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
     dojo.declare(
         "openils.AutoSuggestStore", null, {
 
-        "limit": 10,
-        "last_fetch": null,
-        "org_unit_getter": null,
-        "highlight_max": null,
-        "highlight_min": null,
-        "short_word_length": null,
+        "_last_fetch": null,        /* used internally */
+
+        /* Everything between here and the constructor can be specified in
+         * the constructor's args object. */
+
+        "type_selector": null,      /* HTMLSelect object w/ options whose values
+                                       are search_classes (required) */
+        "org_unit_getter": null,    /* function that returns int (OU ID) */
+
+        "limit": 10,                /* number of suggestions at once */
+        "highlight_max": null,      /* TS_HEADLINE()'s MaxWords option */
+        "highlight_min": null,      /* TS_HEADLINE()'s MinWords option */
+        "short_word_length": null,  /* TS_HEADLINE()'s ShortWord option */
+        "normalization": null,      /* TS_RANK_CD()'s normalization argument */
 
         "constructor": function(/* object */ args) {
             dojo.mixin(this, args); /* XXX very sloppy */
@@ -89,7 +97,8 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
                 params.push("org_unit=" + this.org_unit_getter());
 
             dojo.forEach(
-                ["highlight_max", "highlight_min", "short_word_length"],
+                ["highlight_max", "highlight_min",
+                    "short_word_length", "normalization"],
                 dojo.hitch(this, function(arg) {
                     if (this[arg] != null)
                         params.push(arg + "=" + this[arg]);
@@ -211,7 +220,7 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
 
             var self = this;
             var process_fetch = function(obj, when) {
-                if (when < self.last_fetch) /* Stale response. Discard. */
+                if (when < self._last_fetch) /* Stale response. Discard. */
                     return;
 
                 dojo.forEach(
@@ -246,7 +255,7 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
             if (typeof req.onBegin == "function")
                 req.onBegin.call(callback_scope, -1, req);
 
-            var fetch_time = this.last_fetch = (new Date().getTime());
+            var fetch_time = this._last_fetch = (new Date().getTime());
 
             dojo.xhrGet({
                 "url": url,