From c1838ed376e8942e6069661678bd008bd7a657d5 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Wed, 25 Jan 2012 13:03:43 -0500 Subject: [PATCH] 1) Make ts_rank_cd()'s normalization option controllable from UI level, 2) add some comments here and there about such options that you can control through AutoSuggestStore Signed-off-by: Lebbeous Fogle-Weekley --- .../src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm | 8 ++++++- Open-ILS/src/sql/Pg/030.schema.metabib.sql | 16 ++++++++----- .../sql/Pg/upgrade/YYYY.schema.bib_autosuggest.sql | 16 ++++++++----- Open-ILS/web/js/dojo/openils/AutoSuggestStore.js | 27 ++++++++++++++-------- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm index 30082fd6c3..3e4d18247d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm @@ -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 ) ); diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql index 150e18ad22..331e0c5f88 100644 --- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql +++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql @@ -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 diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib_autosuggest.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib_autosuggest.sql index e03f13cc24..9f8c6638fa 100644 --- a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib_autosuggest.sql +++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib_autosuggest.sql @@ -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 diff --git a/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js b/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js index 5f24202aa7..dab271f562 100644 --- a/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js +++ b/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js @@ -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, -- 2.11.0