From 385c0157e4f4b4d26e6e9effbc2b2325435d5e50 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 26 Apr 2023 13:53:45 -0400 Subject: [PATCH] LP#1997485: Include authority headings in symspell dict This patch adjusts the generation of search suggestions based on authority headings by: * Including all indexed authority headings (1XX, 4XX, and 5XX) from authority records for author, title, and subject headings in the search suggestion dictionary. * As a consequence, suggestions can be based entirely on headings found in authority 4XX and 5XX fields without those headings also needing to be directly in at least one bibliographic record. Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- .../YYYY.schema.DYM-authority-data-dictionary.sql | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/upgrade/YYYY.schema.DYM-authority-data-dictionary.sql diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.DYM-authority-data-dictionary.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.DYM-authority-data-dictionary.sql new file mode 100644 index 0000000000..55fd4191ae --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.DYM-authority-data-dictionary.sql @@ -0,0 +1,94 @@ +BEGIN; + +-- Bring authorized headings into the symspell dictionary. Side +-- loader should be used for Real Sites. See below the COMMIT. +/* +SELECT search.symspell_build_and_merge_entries(h.value, m.field_class, NULL) + FROM authority.simple_heading h + JOIN authority.control_set_auth_field_metabib_field_map_refs a ON (a.authority_field = a.atag) + JOIN config.metabib_field m ON (a.metabib_field=m.id); +*/ + +CREATE OR REPLACE FUNCTION search.symspell_maintain_entries () RETURNS TRIGGER AS $f$ +DECLARE + search_class TEXT; + new_value TEXT := NULL; + old_value TEXT := NULL; +BEGIN + + IF TG_TABLE_SCHEMA = 'authority' THEN + SELECT m.field_class INTO search_class + FROM authority.control_set_auth_field_metabib_field_map_refs a + JOIN config.metabib_field m ON (a.metabib_field=m.id) + WHERE a.authority_field = NEW.atag; + + IF NOT FOUND THEN + RETURN NULL; + END IF; + ELSE + search_class := COALESCE(TG_ARGV[0], SPLIT_PART(TG_TABLE_NAME,'_',1)); + END IF; + + IF TG_OP IN ('INSERT', 'UPDATE') THEN + new_value := NEW.value; + END IF; + + IF TG_OP IN ('DELETE', 'UPDATE') THEN + old_value := OLD.value; + END IF; + + PERFORM * FROM search.symspell_build_and_merge_entries(new_value, search_class, old_value); + + RETURN NULL; -- always fired AFTER +END; +$f$ LANGUAGE PLPGSQL; + +CREATE TRIGGER maintain_symspell_entries_tgr + AFTER INSERT OR UPDATE OR DELETE ON authority.simple_heading + FOR EACH ROW EXECUTE PROCEDURE search.symspell_maintain_entries(); + +COMMIT; + +-- Generate symspell sideloader data with authority headings included. + +/* + +\a +\t + +\o title +select value from metabib.title_field_entry; +select h.value + from authority.simple_heading h + join authority.control_set_auth_field_metabib_field_map_refs a on (a.authority_field = a.atag) + join config.metabib_field m on (a.metabib_field=m.id and m.field_class='title'); + +\o author +select value from metabib.author_field_entry; +select h.value + from authority.simple_heading h + join authority.control_set_auth_field_metabib_field_map_refs a on (a.authority_field = a.atag) + join config.metabib_field m on (a.metabib_field=m.id and m.field_class='author'); + +\o subject +select value from metabib.subject_field_entry; +select h.value + from authority.simple_heading h + join authority.control_set_auth_field_metabib_field_map_refs a on (a.authority_field = a.atag) + join config.metabib_field m on (a.metabib_field=m.id and m.field_class='subject'); + +\o series +select value from metabib.series_field_entry; + +\o identifier +select value from metabib.identifier_field_entry; + +\o keyword +select value from metabib.keyword_field_entry; + +\o +\a +\t + +*/ + -- 2.11.0