LP#1501781 - Make patron name search diacritic/space insensitive.
authorDan Pearl <dpearl@cwmars.org>
Thu, 1 Oct 2015 13:49:17 +0000 (09:49 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 9 Aug 2016 16:37:31 +0000 (12:37 -0400)
Diacritical marks may exist in the patron record, as they should, but
this makes patron name search difficult for librarians who may be
unfamiliar with all the special characters used and also how to elicit
them from a keyboard.  To ease this, accented characters will be
converted into their 'plain' analogs for comparison purposes.

So, for example, if the patron's last name is Chávez, typing "Chavez"
in the Last Name box in Patron Search will match it.

Spaces in a name (like "De la Croix") will be squashed out so that
name would be matched by "Delacroix" or "De la Croix" or variants.

The librarian can enter the accented characters or not.

Signed-off-by: Dan Pearl <dpearl@cwmars.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/src/sql/Pg/000.functions.general.sql
Open-ILS/src/sql/Pg/005.schema.actors.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/create_database_extensions.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron_unaccent.sql [new file with mode: 0644]
docs/RELEASE_NOTES_NEXT/Client/accent_insensitive_patron_search [new file with mode: 0644]

index ad6182e..9b95af8 100644 (file)
@@ -86,4 +86,12 @@ END
 $protect_reserved$
 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')));
+       END;
+$$ LANGUAGE PLPGSQL;
+
+
 COMMIT;
index da94af0..d7e3e6c 100644 (file)
@@ -82,6 +82,9 @@ CREATE INDEX actor_usr_billing_address_idx ON actor.usr (billing_address);
 CREATE INDEX actor_usr_first_given_name_idx ON actor.usr (evergreen.lowercase(first_given_name));
 CREATE INDEX actor_usr_second_given_name_idx ON actor.usr (evergreen.lowercase(second_given_name));
 CREATE INDEX actor_usr_family_name_idx ON actor.usr (evergreen.lowercase(family_name));
+CREATE INDEX actor_usr_first_given_name_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(first_given_name));
+CREATE INDEX actor_usr_second_given_name_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(second_given_name));
+CREATE INDEX actor_usr_family_name_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(family_name));
 
 CREATE INDEX actor_usr_usrname_idx ON actor.usr (evergreen.lowercase(usrname));
 CREATE INDEX actor_usr_email_idx ON actor.usr (evergreen.lowercase(email));
index 46825ea..c8960b1 100644 (file)
@@ -16297,3 +16297,23 @@ INSERT INTO config.org_unit_setting_type
             'coust', 'description'),
         'integer');
 
+INSERT INTO config.org_unit_setting_type
+( name, grp, label, description, datatype )
+VALUES
+('circ.patron_search.diacritic_insensitive',
+ 'circ',
+ oils_i18n_gettext('circ.patron_search.diacritic_insensitive',
+     'Patron search diacritic insensitive',
+     'coust', 'label'),
+ oils_i18n_gettext('circ.patron_search.diacritic_insensitive',
+     'Match patron last, first, and middle names irrespective of usage of diacritical marks or spaces. (e.g., Ines will match Inés; de la Cruz will match Delacruz)',
+     'coust', 'description'),
+  'bool');
+
+INSERT INTO actor.org_unit_setting (
+    org_unit, name, value
+) VALUES (
+    (SELECT id FROM actor.org_unit WHERE parent_ou IS NULL),
+    'circ.patron_search.diacritic_insensitive',
+    'true'
+);
index ed0a964..013032c 100644 (file)
@@ -20,3 +20,4 @@ CREATE EXTENSION xml2;
 CREATE EXTENSION hstore;
 CREATE EXTENSION intarray;
 CREATE EXTENSION pgcrypto;
+CREATE EXTENSION unaccent;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron_unaccent.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron_unaccent.sql
new file mode 100644 (file)
index 0000000..3ec260b
--- /dev/null
@@ -0,0 +1,43 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE EXTENSION IF NOT EXISTS unaccent SCHEMA public;
+
+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')));
+       END;
+$$ LANGUAGE PLPGSQL;
+
+-- The unaccented indices for patron name fields
+CREATE INDEX actor_usr_first_given_name_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(first_given_name));
+CREATE INDEX actor_usr_second_given_name_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(second_given_name));
+CREATE INDEX actor_usr_family_name_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(family_name));
+
+-- DB setting to control behavior; true by default
+INSERT INTO config.org_unit_setting_type
+( name, grp, label, description, datatype )
+VALUES
+('circ.patron_search.diacritic_insensitive',
+ 'circ',
+ oils_i18n_gettext('circ.patron_search.diacritic_insensitive',
+     'Patron search diacritic insensitive',
+     'coust', 'label'),
+ oils_i18n_gettext('circ.patron_search.diacritic_insensitive',
+     'Match patron last, first, and middle names irrespective of usage of diacritical marks or spaces. (e.g., Ines will match Inés; de la Cruz will match Delacruz)',
+     'coust', 'description'),
+  'bool');
+
+INSERT INTO actor.org_unit_setting (
+    org_unit, name, value
+) VALUES (
+    (SELECT id FROM actor.org_unit WHERE parent_ou IS NULL),
+    'circ.patron_search.diacritic_insensitive',
+    'true'
+);
+
+
+COMMIT;
+
diff --git a/docs/RELEASE_NOTES_NEXT/Client/accent_insensitive_patron_search b/docs/RELEASE_NOTES_NEXT/Client/accent_insensitive_patron_search
new file mode 100644 (file)
index 0000000..fed2892
--- /dev/null
@@ -0,0 +1,20 @@
+Accent Insensitive Patron Search
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+When performing a patron search, in addition to the (existing)
+case-insensitivity, these additional characteristics will govern the
+search:
+
+Accent (diacritic) insensitivity::
+Diacritics will be transformed into a plain character equivalent for
+comparison purposes. So if the patron name is Eugène Delacroix, for
+example, you could enter euge for the First Name, and it would
+match. Ligatures such as Œ are expanded into the constituent
+characters "OE".
+
+Space insensitivity::
+Spaces will be squashed out for comparison purposes. If the patron is,
+again, Eugène Delacroix, you could enter "de la croix" in the Last
+Name field and it would match.
+
+This behavior affects the Last Name, First Name, and Middle Name fields
+of the search.