Search quality starts with deciding what a person is trying to find. A platform containing articles, snippets, and tools should not treat every record as an interchangeable text blob. Each content type has different fields, freshness rules, and useful filters.
Begin with a contract
Define the response shape before choosing an index: result ID, canonical URL, title, short excerpt, type, author, and any relevant date. Exclude drafts and private records in the query path, not merely in the UI. Normalize whitespace and punctuation, but preserve code identifiers and language names because developers often search for exact symbols.
For a small corpus, PostgreSQL full-text search can be a sensible first implementation. It keeps writes and search data close together and avoids operating another service. Add a dedicated engine when measured needs justify it, such as typo tolerance, complex facets, or independent search scaling. If indexing asynchronously, define how updates and deletions reach the index and how stale results are handled.
Rank for the task
Exact title or identifier matches should usually outrank a mention deep in the body. Boost recently updated content only when recency is meaningful; otherwise a newer, shallow page can crowd out a better reference. Add filters for type or topic only when they help users narrow results, and make active filters visible and removable.
Compare the result and the query plan
A source-of-truth search can start with PostgreSQL full-text search. Tokenizing a query with plainto_tsquery applies the chosen text-search configuration. A GIN expression index can accelerate a matching to_tsvector expression. In the experiment below, the partial index covers published rows, so the query repeats the publication predicate. PostgreSQL text search indexes
In a PostgreSQL 16.14 test with 10,000 generated rows, every hundredth title contained “draft recovery.” Rows divisible by three were unpublished. The query returned 67 public matches both before and after indexing. The plan changed from a sequential scan to a bitmap index scan followed by a heap scan. This checks that the index changes access cost while preserving the result set. Real ranking still needs examples from the site, including exact titles, acronyms, and terms a reader reasonably expects to find. PostgreSQL EXPLAIN
Worked example
Paste this fixture into a disposable PostgreSQL session. Compare the actual row count and the scan nodes. Small instances or different selectivity can make PostgreSQL choose a different plan.
sqlCREATE TEMP TABLE examples(id integer PRIMARY KEY, title text, published boolean); INSERT INTO examples SELECT n, CASE WHEN n % 100 = 0 THEN 'draft recovery' ELSE 'operational notes' END, n % 3 <> 0 FROM generate_series(1, 10000) n; ANALYZE examples; EXPLAIN (ANALYZE, BUFFERS, TIMING OFF) SELECT id FROM examples WHERE published AND to_tsvector('english', title) @@ plainto_tsquery('english', 'draft recovery'); CREATE INDEX examples_title_search ON examples USING gin (to_tsvector('english', title)) WHERE published; ANALYZE examples; EXPLAIN (ANALYZE, BUFFERS, TIMING OFF) SELECT id FROM examples WHERE published AND to_tsvector('english', title) @@ plainto_tsquery('english', 'draft recovery');




Community
Discussion
Loading comments…