Patch from Niles Ingalls to make patron phone number searching more matchy.
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 5 May 2011 16:40:08 +0000 (16:40 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 5 May 2011 16:40:08 +0000 (16:40 +0000)
With assistance from Mike Rylander on pointing out the needed indexes to keep
search fast, and from Mike Peters on arranging a last minute DCO :-)

Type numbers into a patron phone number field and get a match regardless of
the punctuation actually used in the database.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@20429 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/005.schema.actors.sql
Open-ILS/src/sql/Pg/upgrade/0530.schema.actor-usr-index-phone-fields-more.sql [new file with mode: 0644]

index cd3d4b5..1cb3dce 100644 (file)
@@ -680,7 +680,11 @@ sub patron_search {
        my @phonev;
        if ($pv) {
                for my $p ( qw/day_phone evening_phone other_phone/ ) {
-                       push @ps, "evergreen.lowercase($p) ~ ?";
+                       if ($pv =~ /^\d+$/) {
+                               push @ps, "evergreen.lowercase(REGEXP_REPLACE($p, '[^0-9]', '', 'g')) ~ ?";
+                       } else {
+                               push @ps, "evergreen.lowercase($p) ~ ?";
+                       }
                        push @phonev, "^$pv";
                }
                $phone = '(' . join(' OR ', @ps) . ')';
index ff48b1e..cf59bc0 100644 (file)
@@ -86,7 +86,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0529', :eg_version); -- miker, for Joseph Lewis and Michael Peters
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0530', :eg_version); -- senator, for Niles Ingalls
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index f87ffa0..d56e644 100644 (file)
@@ -88,6 +88,15 @@ CREATE INDEX actor_usr_day_phone_idx ON actor.usr (evergreen.lowercase(day_phone
 CREATE INDEX actor_usr_evening_phone_idx ON actor.usr (evergreen.lowercase(evening_phone));
 CREATE INDEX actor_usr_other_phone_idx ON actor.usr (evergreen.lowercase(other_phone));
 
+CREATE INDEX actor_usr_day_phone_idx_numeric ON actor.usr USING BTREE
+    (evergreen.lowercase(REGEXP_REPLACE(day_phone, '[^0-9]', '', 'g')));
+
+CREATE INDEX actor_usr_evening_phone_idx_numeric ON actor.usr USING BTREE
+    (evergreen.lowercase(REGEXP_REPLACE(evening_phone, '[^0-9]', '', 'g')));
+
+CREATE INDEX actor_usr_other_phone_idx_numeric ON actor.usr USING BTREE
+    (evergreen.lowercase(REGEXP_REPLACE(other_phone, '[^0-9]', '', 'g')));
+
 CREATE INDEX actor_usr_ident_value_idx ON actor.usr (evergreen.lowercase(ident_value));
 CREATE INDEX actor_usr_ident_value2_idx ON actor.usr (evergreen.lowercase(ident_value2));
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/0530.schema.actor-usr-index-phone-fields-more.sql b/Open-ILS/src/sql/Pg/upgrade/0530.schema.actor-usr-index-phone-fields-more.sql
new file mode 100644 (file)
index 0000000..c8dd6d3
--- /dev/null
@@ -0,0 +1,14 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0530'); -- senator
+
+CREATE INDEX actor_usr_day_phone_idx_numeric ON actor.usr USING BTREE 
+    (evergreen.lowercase(REGEXP_REPLACE(day_phone, '[^0-9]', '', 'g')));
+
+CREATE INDEX actor_usr_evening_phone_idx_numeric ON actor.usr USING BTREE 
+    (evergreen.lowercase(REGEXP_REPLACE(evening_phone, '[^0-9]', '', 'g')));
+
+CREATE INDEX actor_usr_other_phone_idx_numeric ON actor.usr USING BTREE 
+    (evergreen.lowercase(REGEXP_REPLACE(other_phone, '[^0-9]', '', 'g')));
+
+COMMIT;