From e99c98adf5c7983325471c15cd0177c3710379f5 Mon Sep 17 00:00:00 2001 From: Joon Park Date: Tue, 31 Jan 2017 16:45:35 -0600 Subject: [PATCH] Add synonyms to search_metadata table's document column. Previously for local testing a postgres thesaurus was used, but this feature is not deployable. Thus, after creating the search_metadata table in the indexing sql script, we manually check for common synonyms such as Ft. and Fort or St. and Saint, then concatenate the synonyms (cast as a tsvector) to the document. --- full-text-search/metadata_script.sql | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/full-text-search/metadata_script.sql b/full-text-search/metadata_script.sql index cbdbe0f..80edca3 100644 --- a/full-text-search/metadata_script.sql +++ b/full-text-search/metadata_script.sql @@ -21,7 +21,7 @@ CREATE TABLE search_metadata AS ( CAST(population as text) as text5, CAST(priority as text) as text6, 'profile' AS type, - document AS document + document AS document -- add conditional and document || to tsvector FROM ( SELECT display_name, sumlevel, full_geoid, population, priority, setweight(to_tsvector('simple', coalesce(display_name, ' ')), 'A') || @@ -155,3 +155,11 @@ UPDATE search_metadata SET text3 = 'unified school district' WHERE text2 = '970' ALTER TABLE search_metadata OWNER TO census; CREATE INDEX ON search_metadata (type); CREATE INDEX ON search_metadata USING GIN(document); + +-- Synonym support +UPDATE search_metadata SET document = document || to_tsvector('simple', coalesce('saint', ' ')) WHERE text1 LIKE '%St.%' AND type = 'profile'; +UPDATE search_metadata SET document = document || to_tsvector('simple', coalesce('st', ' ')) WHERE text1 LIKE '%Saint%' AND type = 'profile'; +UPDATE search_metadata SET document = document || to_tsvector('simple', coalesce('fort', ' ')) WHERE text1 LIKE '%Ft%' AND type = 'profile'; +UPDATE search_metadata SET document = document || to_tsvector('simple', coalesce('ft', ' ')) WHERE text1 LIKE '%Fort%' AND type = 'profile'; +UPDATE search_metadata SET document = document || to_tsvector('simple', coalesce('number', ' ')) WHERE text1 LIKE '%No.%' AND type = 'profile'; +UPDATE search_metadata SET document = document || to_tsvector('simple', coalesce('no', ' ')) WHERE text1 LIKE '%Number%' AND type = 'profile';