Full-Text Search and PostgresSQL Extensions PDF
Full-Text Search and PostgresSQL Extensions PDF
text search
F U N C T I O N S F O R M A N I P U L AT I N G D ATA I N P O S TG R E S Q L
Brian Piccolo
Sr. Director, Digital Strategy
Topics
Full Text search
Extending PostgreSQL
+----------------------+
| title |
+----------------------+
| ELF PARTY |
+----------------------+
+----------------------+
| title |
+----------------------+
| ENCINO ELF |
| GHOSTBUSTERS ELF |
+----------------------+
+----------------------+
| title |
+----------------------+
WHERE to_tsvector(title) @@ to_tsquery('elf'); this statement? accounts for variation and is case insensitive
+----------------------+
| title |
+----------------------+
| ELF PARTY |
| ENCINO ELF |
| GHOSTBUSTERS ELF |
+----------------------+
Stemming
Spelling mistakes
Ranking
SELECT to_tsvector(description)
FROM film;
Brian Piccolo
Sr. Director, Digital Strategy
User-de ned data types
Enumerated data types
WHERE typname='dayofweek';
+-----------+-------------+
| typname | typcategory |
|-----------|-------------|
| dayofweek | E |
+-----------+-------------+
E= enum type
+-----------------------------------------------+
| column_name | data_type | udt_name |
|-------------|-------------------|-------------|
| title | character varying | varchar |
| rating | USER-DEFINED | mpaa_rating |
+-----------------------------------------------+
SELECT squared(10);
+---------+
| squared |
|---------|
| 100 |
+---------+
Brian Piccolo
Sr. Director, Digital Strategy
Intro to PostgreSQL extensions
Commonly used extensions
PostGIS adds support for allowing location queries to be run in sql
fuzzystrmatch
extend full text search capabilities by finding similarities between strings
pg_trgm
+--------------------+ +---------+
| name | | name |
|--------------------| |---------|
| dblink | | plpgsql |
| pg_stat_statements | +---------+
+--------------------+
+---------------+
| name |
|---------------|
| plpgsql |
| fuzzystrmatch |
+---------------+
+-------------+
| levenshtein |
|-------------|
| 2 |
+-------------+
+------------+
| similarity |
|------------|
| 0.18181818 |
+------------+
determie the similarity of two strings using trigram 8groups of 3 consecutive chars in a str) matchings
SELECT
title,
Next, create a new column using the description,
similarity function to rank the film -- Calculate the similarity
Let's practice!
descriptions based on this phrase. similarity(description, 'Astounding Drama')
FROM
film
WHERE
to_tsvector(description) @@
to_tsquery('Astounding & Drama')
ORDER BY
F U N C T I O N S F O R M A N I P U L AT I N G D ATA I N P O S TG R E S Q L
similarity(description, 'Astounding Drama') DESC;
Putting it All
Together
F U N C T I O N S F O R M A N I P U L AT I N G D ATA I N P O S TG R E S Q L
Brian Piccolo
Sr. Director, Digital Strategy
Functions for manipulating data recap and review
Common data types in PostgreSQL