Urgent.News

What's breaking now, across thousands of outlets.

Tech

Our search endpoint returns three fields, and its WHERE clause is copied out of an index definition on purpose

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…

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.

The 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.

Matching 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.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Momentloom: Let the right video find you

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady Every Short starts with a small question: which video is worth my time?

  • Momentloom simplifies turning long YouTube videos into short clips.
  • App identifies promising moments and creates Shorts with Hype score.
  • Users can customize filters, set filters, and add captions to clips.

Our healthy shopping row is never green, and its off switch is an empty array

Munchable's result screen, after you scan something, is a stack of rows. Some are about the conditions you told it you have . Some are about allergies.

  • Healthy shopping row lists ingredients to avoid, no cautionary statement
  • Allergy row includes permanent caution about allergens
  • Distinct visual cues differentiate row types for clarity

More from Saturday 24 October →