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>
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;
BEGIN;
-- Number of tests that will be run
-SELECT plan(15);
+SELECT plan(18);
-- Run the tests
'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');
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;
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;
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));
+-- If the above is executed and the indices already exist, 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;
+
+
-- DB setting to control behavior; true by default
INSERT INTO config.org_unit_setting_type
( name, grp, label, description, datatype )
--- /dev/null
+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.
+
+