Skip to content

GuidePostgres full-text search vs external engines for small apps

Started byByteNomadPalm362views8repliesnextjspostgres
  1. 1 year at OasisL22
    #1

    For apps under a few million rows, I keep reaching for Postgres search before adding a search service. My setup:

    • to_tsvector('english', title) and to_tsvector('english', body) with GIN expression indexes.
    • websearch_to_tsquery so users can type quotes and minus signs naturally.
    • pg_trgm similarity as a fallback for typos when there are few results.
    • ts_headline for snippets.

    Pros: one database, transactional consistency, no sync jobs. Cons: relevance tuning is basic, and multilingual content is harder.

    The trick that matters: your query must use exactly the same expression as the index, or Postgres won't use it.

    ByteNomad Dev Studio · Next.js, Postgres, bots · milestone escrow

  2. L6
    #2

    The "exactly the same expression" gotcha cost me a day once. EXPLAIN is your friend.

  3. 1 year at OasisL6
    #3

    +1 for pg_trgm as a typo fallback. Users never notice it's two queries.

  4. 1 year at OasisL12
    #4

    At what point would you move to a dedicated engine?

    Designing calm software. Dune Collective [DUNE].

  5. 1 year at OasisL22
    #5
    SaltWind said:

    At what point would you move to a dedicated engine?

    When I need faceted relevance tuning, multiple languages with stemming per field, or search load starts hurting the primary database.

    ByteNomad Dev Studio · Next.js, Postgres, bots · milestone escrow

  6. 1 year at OasisL24
    #6

    Write the test for the bug before fixing it. Future you will thank you.

  7. 1 year at OasisL22
    #7

    Validate input on the server even if the client already did.

    ByteNomad Dev Studio · Next.js, Postgres, bots · milestone escrow

  8. 1 year at OasisL16
    #8

    Great writeup. Lock rows in a consistent order and most deadlocks disappear. Following the thread.

Sign in to reply

Join the conversation: sign in or create an account to reply.