Goal: Compare character patterns with normalized word search, then explain each match using the stored terms and query operators.
Connect to beer_db as student. You will read the real names, descriptions, and generated description_tsv column; no course data is changed. The provided COUNT queries summarize full match sets, while LIMIT queries show previews.
Preview five names beginning with Premium, then five containing Aged anywhere. % matches zero or more characters, so its placement matters. Next try _old%: _ matches exactly one character before old. The literal comparison returns t for Gold and f for XXold, which has two leading characters. Ordered previews do not count every match.
Keep the same lowercase pattern %marzen%. LIKE returns zero rows on these names; ILIKE returns capitalized Marzen names. Show five matches, then count the full set: 26, not five. ILIKE ignores case according to the active locale; it does not automatically remove accents such as ä.
Inspect beers and find description_tsv, its generated English-language expression, and the separate GIN index idx_beers_fts. Query descriptions matching tropical, preview five in a repeatable order, then count all 24 matches. to_tsquery normalizes the search input; @@ tests the stored vector.
An eligible GIN index does not mean every query automatically uses it; this is a matching exercise, not a plan or speed measurement.
Compare exactly the same two search terms, citrus and hop. COUNT(*) returns zero documents for & (both terms required), then 96 for | (either term). Both queries display one count row. Preview five OR matches afterwards and inspect why each qualifies. A broader match set is not itself evidence that the results are relevant to a user's intent.
Preview five documents matching both tropical and fruit. ts_headline formats the original description using the same English query as the WHERE predicate. MaxWords=15 and MinWords=5 guide snippet size; AS snippet labels the output. Matched words have literal <b> markers in psql, not browser-rendered bold text. The function produces a snippet; it does not decide which rows qualify.
Inspect the two different beers called Seasonal Ale. The description beginning Dry-hopped has lexeme tropic and returns t for the tropical query; the Deep amber description returns f. tsvector_to_array exposes the distinct normalized terms from the generated column, without their positions. This is not a dump of GIN index storage. Name is not a unique beer identifier, so both rows belong in the result.
Compare all three terms tropical, citrus, and fruit. With both operators set to &, no description has all three normalized terms. Change both operators to | and count 62 descriptions with at least one term. This changes two operator characters, and zero to 62 is not a 62-fold ratio. COUNT(*) reports complete match counts without flooding the terminal with 62 names.
Inspect the query values produced by phraseto_tsquery for passion fruit and by to_tsquery with the explicit <-> operator. Both normalize to passion immediately followed by fruit; a direct equality comparison returns t. Then compare two labelled text literals: passion fruit matches, while passion sweet fruit does not. The intervening retained word breaks adjacency. This SELECT demonstration saves no documents.
Normalize the query tropical and observe tropic. Inspect Crisp IPA, whose description contains tropical and whose vector contains tropic, then test that named row directly: matches is t. Finally compare the literal hoppy with the query hop. English normalization gives different lexemes (hoppi versus hop), so the word match is f, although the substring ILIKE %hop% is t.
Shared letters are not the same rule as equal search lexemes.