Challenge - 5 Problems
Search Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of a full-text search with language configuration
Given a table
Assume the table has these rows:
1. 'The cat chased the dog.'
2. 'A dog and a cat are friends.'
3. 'Cats are independent animals.'
documents with a content column, what is the output of this query?SELECT content FROM documents WHERE to_tsvector('english', content) @@ to_tsquery('english', 'cat & dog');Assume the table has these rows:
1. 'The cat chased the dog.'
2. 'A dog and a cat are friends.'
3. 'Cats are independent animals.'
PostgreSQL
CREATE TABLE documents (content TEXT); INSERT INTO documents VALUES ('The cat chased the dog.'), ('A dog and a cat are friends.'), ('Cats are independent animals.'); SELECT content FROM documents WHERE to_tsvector('english', content) @@ to_tsquery('english', 'cat & dog');
Attempts:
2 left
💡 Hint
Remember that the query looks for rows containing both 'cat' and 'dog' after stemming and stop-word removal.
✗ Incorrect
The query uses the English text search configuration. It looks for rows where both 'cat' and 'dog' appear. The first two rows contain both words, so they match. The third row only contains 'cats' (plural), which is stemmed to 'cat', but it does not contain 'dog', so it does not match.
🧠 Conceptual
intermediate1:30remaining
Purpose of search configuration languages in PostgreSQL
What is the main purpose of specifying a language in PostgreSQL's full-text search configuration?
Attempts:
2 left
💡 Hint
Think about how words are reduced to their root forms and common words are ignored.
✗ Incorrect
Specifying a language in full-text search tells PostgreSQL which stemming rules and stop-word lists to use. This helps match different forms of words and ignore common words that do not add meaning.
📝 Syntax
advanced2:00remaining
Correct syntax to create a custom text search configuration
Which of the following commands correctly creates a new text search configuration named
my_english based on the built-in english configuration?Attempts:
2 left
💡 Hint
The syntax uses COPY to duplicate an existing configuration.
✗ Incorrect
The correct syntax to create a new configuration based on an existing one is to use COPY with parentheses. Other options are invalid syntax.
🔧 Debug
advanced2:00remaining
Why does this full-text search query return no results?
Consider this query:
Given that
SELECT * FROM articles WHERE to_tsvector('simple', body) @@ to_tsquery('english', 'databases');Given that
body contains the word 'databases' in some rows, why might this query return no rows?Attempts:
2 left
💡 Hint
Check if the text search configurations match in both functions.
✗ Incorrect
The
to_tsvector uses the 'simple' configuration, which does no stemming or stop-word removal, while to_tsquery uses 'english', which applies stemming and stop-word removal. This mismatch causes the query to fail to match.❓ optimization
expert3:00remaining
Optimizing full-text search for multiple languages
You have a multilingual table with a
Which approach is the best to optimize search performance?
content column and a language column specifying the language of each row (e.g., 'english', 'french'). You want to create a full-text search index that respects each row's language for stemming and stop-word removal.Which approach is the best to optimize search performance?
Attempts:
2 left
💡 Hint
Think about how to store and index the tsvector efficiently for multiple languages.
✗ Incorrect
Using
to_tsvector(language, content) stores the language-specific processed text in one column, allowing a single GIN index to be used efficiently for all rows regardless of language. Separate columns and indexes increase complexity and storage.