{
  "id": 16302502,
  "title": "Our search endpoint returns three fields, and its WHERE clause is copied out of an index definition on purpose",
  "url": "https://urgent.news/2026/10/24/our-search-endpoint-returns-three-fields-and-its-where-clause-is",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-24T08:41:31.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/daniel_pertu/our-search-endpoint-returns-three-fields-and-its-where-clause-is-copied-out-of-an-index-definition-5g1n"
  },
  "original_language": "en",
  "account": "Munchable's search endpoint is designed to return only three fields - barcode, productName, and brands. The endpoint does not have access to the full product data, so when a user taps on a search result, it triggers a POST request to /api/product-lookup using the barcode to fetch the complete product information. This architectural decision ensures that the search route does not have to manage product data or be aware of cache, trust status, or quota information.\n\nThe search process involves writing SQL fragments that define how to search the database. The searchable text is created by concatenating the productName and brands fields, separated by spaces. A partial GIN trigram index is created on this expression to improve search performance. The index predicate is also written as an SQL fragment and must match the query where clause exactly for the partial index to be effective.\n\nMatching is done per word, rather than as a single phrase, allowing for more flexible search queries. Each word in the query is compared against the productName and brands fields, rather than treating the search term as a single phrase. This approach ensures that queries like \"alpro oat\" match the product named \"Oat drink\" correctly, even though they are searched for separately.",
  "summary": "Munchable's main input is a camera pointed at a barcode. That is useless to somebody writing a shopping list on the sofa, so there is also a search screen: type a name, tap a result, get the same answer you would have got in the aisle. The interesting thing about building it was how little the new code was allowed to know. This post is the route, the query, and the screen, in that order, with the…",
  "key_points": [
    "Search endpoint returns three fields: barcode, productName, brands",
    "WHERE clause copied from index definition for effective matching",
    "POST request fetches complete product info after search result"
  ],
  "editors_take": "Decoupling search from full product data simplifies the endpoint architecture by removing the need for the search route to manage complex product metadata or caching requirements.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}