egdb3_12_9
.search
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
symspell_build_entries(full_input text, source_class text, old_input text DEFAULT NULL::text, include_phrases boolean DEFAULT false)
Parameters
Name
Type
Mode
full_input
text
IN
source_class
text
IN
old_input
text
IN
include_phrases
boolean
IN
Definition
DECLARE prefix_length INT; maxED INT; word_list TEXT[]; input TEXT; word TEXT; entry search.symspell_dictionary; BEGIN IF full_input IS NOT NULL THEN SELECT value::INT INTO prefix_length FROM config.internal_flag WHERE name = 'symspell.prefix_length' AND enabled; prefix_length := COALESCE(prefix_length, 6); SELECT value::INT INTO maxED FROM config.internal_flag WHERE name = 'symspell.max_edit_distance' AND enabled; maxED := COALESCE(maxED, 3); input := evergreen.lowercase(full_input); word_list := ARRAY_AGG(x) FROM search.symspell_parse_words_distinct(input) x; IF word_list IS NULL THEN RETURN; END IF; IF CARDINALITY(word_list) > 1 AND include_phrases THEN RETURN QUERY SELECT * FROM search.symspell_build_raw_entry(input, source_class, TRUE, prefix_length, maxED); END IF; FOREACH word IN ARRAY word_list LOOP -- Skip words that have runs of 5 or more digits (I'm looking at you, ISxNs) CONTINUE WHEN CHARACTER_LENGTH(word) > 4 AND word ~ '\d{5,}'; RETURN QUERY SELECT * FROM search.symspell_build_raw_entry(word, source_class, FALSE, prefix_length, maxED); END LOOP; END IF; IF old_input IS NOT NULL THEN input := evergreen.lowercase(old_input); FOR word IN SELECT x FROM search.symspell_parse_words_distinct(input) x LOOP -- similarly skip words that have 5 or more digits here to -- avoid adding erroneous prefix deletion entries to the dictionary CONTINUE WHEN CHARACTER_LENGTH(word) > 4 AND word ~ '\d{5,}'; entry.prefix_key := word; entry.keyword_count := 0; entry.title_count := 0; entry.author_count := 0; entry.subject_count := 0; entry.series_count := 0; entry.identifier_count := 0; entry.keyword_suggestions := '{}'; entry.title_suggestions := '{}'; entry.author_suggestions := '{}'; entry.subject_suggestions := '{}'; entry.series_suggestions := '{}'; entry.identifier_suggestions := '{}'; IF source_class = 'keyword' THEN entry.keyword_count := -1; END IF; IF source_class = 'title' THEN entry.title_count := -1; END IF; IF source_class = 'author' THEN entry.author_count := -1; END IF; IF source_class = 'subject' THEN entry.subject_count := -1; END IF; IF source_class = 'series' THEN entry.series_count := -1; END IF; IF source_class = 'identifier' THEN entry.identifier_count := -1; END IF; RETURN NEXT entry; END LOOP; END IF; END;