egdb3_11_7
.search
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
symspell_build_raw_entry(raw_input text, source_class text, no_limit boolean DEFAULT false, prefix_length integer DEFAULT 6, maxed integer DEFAULT 3)
Parameters
Name
Type
Mode
raw_input
text
IN
source_class
text
IN
no_limit
boolean
IN
prefix_length
integer
IN
maxed
integer
IN
Definition
DECLARE key TEXT; del_key TEXT; key_list TEXT[]; entry search.symspell_dictionary%ROWTYPE; BEGIN key := raw_input; IF NOT no_limit AND CHARACTER_LENGTH(raw_input) > prefix_length THEN key := SUBSTRING(key FROM 1 FOR prefix_length); key_list := ARRAY[raw_input, key]; ELSE key_list := ARRAY[key]; END IF; FOREACH del_key IN ARRAY key_list LOOP -- skip empty keys CONTINUE WHEN del_key IS NULL OR CHARACTER_LENGTH(del_key) = 0; entry.prefix_key := del_key; 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_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'title' THEN entry.title_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'author' THEN entry.author_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'subject' THEN entry.subject_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'series' THEN entry.series_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'identifier' THEN entry.identifier_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'keyword' THEN entry.keyword_suggestions := ARRAY[raw_input]; END IF; IF del_key = raw_input THEN 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; END IF; RETURN NEXT entry; END LOOP; FOR del_key IN SELECT x FROM UNNEST(search.symspell_generate_edits(key, 1, maxED)) x LOOP -- skip empty keys CONTINUE WHEN del_key IS NULL OR CHARACTER_LENGTH(del_key) = 0; -- skip suggestions that are already too long for the prefix key CONTINUE WHEN CHARACTER_LENGTH(del_key) <= (prefix_length - maxED) AND CHARACTER_LENGTH(raw_input) > prefix_length; 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 := 0; END IF; IF source_class = 'title' THEN entry.title_count := 0; END IF; IF source_class = 'author' THEN entry.author_count := 0; END IF; IF source_class = 'subject' THEN entry.subject_count := 0; END IF; IF source_class = 'series' THEN entry.series_count := 0; END IF; IF source_class = 'identifier' THEN entry.identifier_count := 0; END IF; entry.prefix_key := del_key; IF source_class = 'keyword' THEN entry.keyword_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'title' THEN entry.title_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'author' THEN entry.author_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'subject' THEN entry.subject_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'series' THEN entry.series_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'identifier' THEN entry.identifier_suggestions := ARRAY[raw_input]; END IF; IF source_class = 'keyword' THEN entry.keyword_suggestions := ARRAY[raw_input]; END IF; RETURN NEXT entry; END LOOP; END;