LP#1613341 - Patron name search should be punctuation-insensitive
authorDan Pearl <dpearl@cwmars.org>
Wed, 8 Feb 2017 22:57:20 +0000 (17:57 -0500)
committerKathy Lussier <klussier@masslnc.org>
Thu, 9 Feb 2017 23:25:18 +0000 (18:25 -0500)
O'Brien will be matched by Obrien, O'Brien, O Brien etc.
Grubbly-Plank will be matched by Grubbly Plank, Grubbly-Plank, Grubblyplank, etc.
This feature is controlled by the same org setting that controls ignoring
of diacritical marks.

Signed-off-by: Dan Pearl <dpearl@cwmars.org>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>

Open-ILS/src/sql/Pg/000.functions.general.sql
Open-ILS/src/sql/Pg/t/lp1501781-unaccent_and_squash.pg
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron_punct.sql [new file with mode: 0644]
docs/RELEASE_NOTES_NEXT/Client/patron_punctuation [new file with mode: 0644]

index 9b95af8..8b0dd63 100644 (file)
@@ -89,7 +89,7 @@ LANGUAGE plpgsql;
 CREATE OR REPLACE FUNCTION evergreen.unaccent_and_squash ( IN arg text) RETURNS text
     IMMUTABLE STRICT AS $$
        BEGIN
-       RETURN evergreen.lowercase(unaccent(regexp_replace(arg, '\s','','g')));
+       RETURN evergreen.lowercase(unaccent(regexp_replace(arg, '[\s[:punct:]]','','g')));
        END;
 $$ LANGUAGE PLPGSQL;
 
index f09dcf6..c90014f 100644 (file)
@@ -2,7 +2,7 @@
 BEGIN;
 
 -- Number of tests that will be run
-SELECT plan(15);
+SELECT plan(18);
 
 -- Run the tests
 
@@ -27,7 +27,7 @@ SELECT is(evergreen.unaccent_and_squash('aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsSt
           'English Characters');
 
 SELECT is(evergreen.unaccent_and_squash('0123456789!@#$%^&*()-+'),
-          '0123456789!@#$%^&*()-+', 'Numbers and Symbols');
+          '0123456789', 'Numbers and Symbols');
 
 SELECT is(evergreen.unaccent_and_squash('ÁÉÍÑÓÚÜáéíñóúü¿¡'),
           'aeinouuaeinouu¿¡', 'Spanish');
@@ -56,6 +56,17 @@ SELECT is(evergreen.unaccent_and_squash('El Niño'),
 SELECT is(evergreen.unaccent_and_squash('Œuvres'),
           'euvres', 'oe ligature');
 
+-- Punctuation Tests
+
+SELECT is(evergreen.unaccent_and_squash('O''Brien'),
+          'obrien', 'Apostrophe');
+
+SELECT is(evergreen.unaccent_and_squash('Grubbly-Plank'),
+          'grubblyplank', 'Hyphen');
+
+SELECT is(evergreen.unaccent_and_squash('p&#$(a#*&$!s))(\\s'),
+          'pass', 'Punctuation hash');
+
 -- Finish the test and clean up.
 SELECT * FROM finish();
 ROLLBACK;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron_punct.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron_punct.sql
new file mode 100644 (file)
index 0000000..3713a3b
--- /dev/null
@@ -0,0 +1,21 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('0986', :eg_version);
+
+CREATE OR REPLACE FUNCTION evergreen.unaccent_and_squash ( IN arg text) RETURNS text
+    IMMUTABLE STRICT AS $$
+       BEGIN
+       RETURN evergreen.lowercase(unaccent(regexp_replace(arg, '[\s[:punct:]]','','g')));
+       END;
+$$ LANGUAGE PLPGSQL;
+
+-- Upon upgrade, we need to
+-- reindex because the definition of the unaccent_and_squash function
+-- has changed.
+REINDEX INDEX actor.actor_usr_first_given_name_unaccent_idx;
+REINDEX INDEX actor.actor_usr_second_given_name_unaccent_idx;
+REINDEX INDEX actor.actor_usr_family_name_unaccent_idx;
+
+COMMIT;
+
+
diff --git a/docs/RELEASE_NOTES_NEXT/Client/patron_punctuation b/docs/RELEASE_NOTES_NEXT/Client/patron_punctuation
new file mode 100644 (file)
index 0000000..75b160c
--- /dev/null
@@ -0,0 +1,10 @@
+Punctuation Insensitive Patron Search
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+When performing a patron search, punctuation characters will be
+ignored.  So if the patron is named O'Brien, then you can enter Obrien,
+O'Brien, O Brien, etc. in the search box.
+
+This behavior affects the Last Name (internally: family_name), First Name
+(first_given_name), and Middle Name (second_given_name) fields of the search.
+
+