Introduction to full-text search

Functions for Manipulating Data in PostgreSQL

Brian Piccolo

Sr. Director, Digital Strategy

Topics

  • Full Text search
  • Extending PostgreSQL
  • Improving full text search with extensions
Functions for Manipulating Data in PostgreSQL

The LIKE operator

_ wildcard: Used to match exactly one character.

% wildcard: Used to match zero or more characters.

SELECT title
FROM film
WHERE title LIKE 'ELF%';
+----------------------+
| title                |
+----------------------+
| ELF PARTY            |
+----------------------+
Functions for Manipulating Data in PostgreSQL

The LIKE operator

SELECT title
FROM film
WHERE title LIKE '%ELF';
+----------------------+
| title                |
+----------------------+
| ENCINO ELF           |
| GHOSTBUSTERS ELF     |
+----------------------+
Functions for Manipulating Data in PostgreSQL

The LIKE operator

SELECT title
FROM film
WHERE title LIKE '%elf%';
+----------------------+
| title                |
+----------------------+
Functions for Manipulating Data in PostgreSQL

LIKE versus full-text search

SELECT title, description
FROM film
WHERE to_tsvector(title) @@ to_tsquery('elf');
+----------------------+
| title                |
+----------------------+
| ELF PARTY            |
| ENCINO ELF           |
| GHOSTBUSTERS ELF     |
+----------------------+
Functions for Manipulating Data in PostgreSQL

What is full-text search?

Full text search provides a means for performing natural language queries of text data in your database.

  • Stemming

  • Spelling mistakes

  • Ranking

Functions for Manipulating Data in PostgreSQL

Full-text search syntax explained

SELECT title, description
FROM film
WHERE to_tsvector(title) @@ to_tsquery('elf');
Functions for Manipulating Data in PostgreSQL

Let's practice!

Functions for Manipulating Data in PostgreSQL

Preparing Video For Download...