API Search & Filtering 00:00:01 Apply filters consistently A buyer enters a word and chooses a price range. The catalogue must decide what may match and then which matching item appears first. Treating all three decisions as a single vague search makes results hard to explain. Every product is returned. Six are electronics. The mouse and the power strip drop out. The keyboard is sold out. Two are left. The hub with 4.8 before the webcam with 4.2. Three columns are sent instead of all. Validate fields and allowable operations before translating a request into a query. A filter constrains the candidate set; it should not secretly redefine the meaning of the user's text. 00:00:47 Break ties deterministically category:asc, then price:desc. The second field only decides inside equal first fields. No order yet. Accessories before electronics. Inside each group the dearest first. Add a stable second ordering field when several products share a price or score. Otherwise paging can skip or repeat items even when no product has changed. 00:01:13 Choose a query vocabulary Price of at least 50, written in five ways. Pick one for the whole API. Easy and everywhere. The operator is part of the name. Field and operator are separate. Stripe uses it for dates. Cannot be confused with page or sort. JSON:API reserves the word filter. Short, but a value may contain a colon itself. Any logic, such as OR across fields. Needs a real parser and limits. Separate a public query contract from the storage expression that implements it. Exposing arbitrary database syntax needlessly couples every client to internal indexes and permissions. 00:01:53 Search words according to a declared analyzer The query Wireless MOUSES through tokens, stems, the inverted index and scores. Built before anyone asks: each word and its documents. Wireless MOUSES becomes wireless, mouse. Documents 1 and 10. Document 1. Document 1 has both: 1.65 plus 2.16 equals 3.81. Document 10 has 1.65. The wireless mouse, then the wireless headphones. Matching an ingredient or product word can involve normalization and tokenization. Use compatible analysis at indexing and query time, and test the treatment of phrases, accents and punctuation that matter to customers. 00:02:39 Build an index for the actual access pattern A change reaches the search index through events, a moment after the database. The name of product 7 changes in the database. A search now still finds the old name. The indexer reads the change. Doing it twice changes nothing. After the next refresh, searches see it. A composite index can help some filter and sort combinations far more than others. Examine how many candidates are read before the engine can return the requested page. 00:03:06 One box can ask different questions Words, filters and fresh prices in one page. wireless, under 100, four stars or more. The search engine returns ranked ids: only product 1 fits. Price and stock are read from the database. Ranked by words, correct in price. If the interface permits free text as well as structured fields, make their interactions explicit. A narrow exact filter should not disappear merely because the text ranker found a popular item. State the matching rule, the ranking order and the continuation point together. A customer can then tell why an item is missing and why another item appeared on the next page.