Goal: search prose by normalized lexemes, rank matches, and inspect index support.
Connect as the tv_db dataset-owner role to tv_db.
In the connection command, -U tv_db selects the SQL role and -d tv_db selects the database. Expect the psql welcome message and a tv_db=> prompt; run the following SQL there.
Goal: observe what English stemming actually normalizes.
Parse investigation, investigate, detective, conspiracy, and conspired into English lexemes. Then compare a literal document with brewed/brewing/brews and a brew query: it matches. Compare conspired with a conspiracy query: it does not. Stemming groups forms by dictionary rules; it is not a synonym or meaning engine.
to_tsvector('english', ...) builds searchable lexemes; displayed numbers are word positions. plainto_tsquery builds a query with the same dictionary, and @@ tests matching. Expect brewed/brewing/brews to match brew (t), but conspired not to match conspiracy (f).
Goal: search for two required concepts using one shared language configuration.
Inspect plainto_tsquery for corporate conspiracy: the terms are ANDed. Search shows.description_tsv using the same English configuration and show every match, ordered by title/id. Neon District is the single matching show. Practice uses show descriptions, not episode descriptions.
plainto_tsquery treats input as plain text rather than query-operator syntax. description_tsv is the prebuilt searchable vector; @@ compares it with the query. Expect exactly Neon District, not any show containing just one term.
Goal: compare explicit OR, AND, and NOT queries before ranking.
Count matches for investigation | detective, investigation & detective, and investigation & !detective on the same shows table. Expect 8 / 2 / 3. Then rank all eight OR matches by ts_rank descending and title/id for ties. These keyword scores are not audience ratings.
to_tsquery accepts query syntax: | means OR, & AND, and ! NOT. The NOT branch is restricted by investigation, not a request for every non-detective show. ts_rank returns a relevance score; expect eight ranked rows after counts 8/2/3.
Goal: make matching words visible in the original prose.
Generate five snippets for the same OR query in title/id order. Set StartSel and StopSel to square brackets so the terminal visibly marks words without raw HTML tags. ts_headline uses the original text and can highlight forms such as investigative; it is not an HTML sanitizer.
ts_headline selects text excerpts; it does not replace the stored description. StartSel/StopSel define the surrounding highlight markers. Expect five snippets with matching terms in square brackets; the ordered preview is not the top-five relevance ranking.
Goal: change both database and SQL role for the review-text search.
Use \c beer_db beer_db to connect explicitly as the beer_db dataset role. The next step searches review text; connecting alone does not perform a search.
In \c beer_db beer_db, the first name is the database and the second the role. This psql command reconnects without returning to the shell. Expect a connection confirmation naming both beer_db values.
Goal: search beer reviews and interpret relevance separately from rating.
Count reviews matching tropical OR aroma and tropical AND aroma. Both counts are 220 in this seed: every matching review contains both lexemes, so OR need not return more rows. Preview five joined beer/reviewer matches with rank and ID tie-breakers. Search rank measures keyword relevance, not positive sentiment or the review score.
review_tsv represents review text; the joins supply beer and reviewer details for each matching review. Expect counts 220/220 followed by five ranked matches. A review is one result row, so a beer may appear more than once.
Goal: verify full-text matching can use the existing GIN index.
Inspect idx_beer_ratings_fts, then in a transaction SET LOCAL enable_seqscan = off, EXPLAIN the review_tsv @@ query, and ROLLBACK. Look for the GIN index and @@ Index Cond. GIN helps find matches; ranking still needs computation/sorting. This controlled plan does not promise that the normal planner selects GIN or that a search is sub-millisecond.
The pg_indexes view supplies its SQL definition in indexdef. SET LOCAL discourages sequential scans only until transaction end; EXPLAIN shows the plan rather than search results. Complete the capability check with ROLLBACK so the temporary planner preference is cleared.