1.  [](/)
2.  [Diagrams](/diagrams)
3.  Sorting by Price Shows the Wrong One First: Landed Cost Computed Inside the Pipeline

[Back to Diagrams](/diagrams)Retrieval Mechanics

# Sorting by Price Shows the Wrong One First: Landed Cost Computed Inside the Pipeline

A real "floor lamp" query, then a sandboxed Python stage applies discount tiers and a shipping threshold to each result. $298.71 lands at $323.66 and $322.38 lands at $308.64, so the two cheapest rows swap. Sort by list price and the wrong lamp is first.

![A portrait diagram. The headline reads Sorting by price, shows the wrong one first, with the subline: discount tiers and a shipping threshold are business rules, not search config, so we ran them inside the pipeline. A five-row table has columns item, list, tier, disc and landed. Steel Floor Lamp, 298.71 dollars, retail, 0 percent, landed 323.66; Brass Floor Lamp, 322.38 dollars, trade, 12 percent, landed 308.64; Wood Floor Lamp, 729.19 dollars, wholesale, 25 percent, landed 546.89; Brass Floor Lamp, 801.62 dollars, wholesale, 25 percent, landed 601.22; Wood Floor Lamp, 907.60 dollars, wholesale, 25 percent, landed 680.70. The first two rows are outlined in rose, with the caption sorted by list price, the two highlighted rows swap once landed cost is computed. A bold line reads 298.71 dollars lands at 323.66, 322.38 dollars lands at 308.64, sort by price and you show the wrong one first. A dark code window labelled code\_execution, python, sandboxed, 5854 ms shows the Python that assigns a tier by price, a discount of 25, 12 or 0 percent, free shipping at or above 500 dollars and 24.95 below, and appends tier, discount\_pct and landed\_cost per document. The footer prints mxp.co/d/code-in-the-pipeline and real query, real execution, mixpeek.](/diagrams/code-in-the-pipeline.webp)Full screen

A real "floor lamp" query, then a sandboxed Python stage applies discount tiers and a shipping threshold to each result. $298.71 lands at $323.66 and $322.38 lands at $308.64, so the two cheapest rows swap. Sort by list price and the wrong lamp is first.

Sort a result set by price and you can still show the wrong item first. The diagram runs a real floor lamp query against a 118 image index, then adds one code\_execution stage: a sandboxed Python block that applies discount tiers and a shipping threshold to each result.

The rules are ordinary. Wholesale at 700 dollars and above takes 25 percent off, trade at 300 and above takes 12 percent, retail pays list. Orders under 500 dollars pay 24.95 shipping. Applied to the five lamps the search returned, 298.71 dollars lands at 323.66 because it sits under the free shipping line, and 322.38 dollars lands at 308.64 because it clears the trade discount. The two cheapest rows swap.

Tiers, thresholds and landed cost are business rules. They change more often than an index does and they belong to whoever owns pricing, so writing them into search configuration would be the wrong place even if the configuration could express them. The stage runs the Python in an isolated sandbox as part of retrieval, so the rule lives next to the query rather than in whichever service happens to render the results. 5.8 seconds for five documents in this run.

Two details of the contract, learned while building this: the sandbox hands the result set to the code as docs, and the computed values land under the stage's output\_field on each document's payload rather than at the document root. Read the root and the stage looks like it did nothing.

The general version is that the answer to whether your search can do some specific thing stops being a roadmap question. If it can be written in a few lines against the matched documents, it can run in the pipeline.

What is real here: the photos behind the rows are Pexels images with every photographer credited, the query and the sandboxed execution ran against the live API, and the landed costs are the ones the stage returned. Prices, tiers and thresholds are demo catalog data and demo rules, so the dollar figures describe the demo and the mechanism is the point.

Run this on your own data

Mixpeek turns video, images, audio, and documents in your object storage into searchable, timestamped results through one API.

[Search your own data](https://studio.mixpeek.com/namespaces/create?mode=managed&utm_source=homepage&utm_medium=diagram_detail&utm_campaign=mvs_onramp)

## Related diagrams

[

![A portrait diagram in two rails. The headline reads Filters exclude, what ranking would have shown, with the subline: a pre\_filter drops rows before ranking is ever shown to you, useful, and it hides what it removed. A search bar holds the query yellow armchair, annotated: three of the top five are out of stock. Rail A, badged no filter, shows five armchair photos in rank order with prices and scores: 872 dollars at 0.080, 515 dollars at 0.065, 180 dollars at 0.060, 451 dollars at 0.060 and 506 dollars at 0.057; the second, third and fourth are greyed and stamped dropped, and the count chip reads 5 of 5. Rail B, badged pre\_filter with in\_stock equals true, shows the two survivors at 872 and 506 dollars followed by three new armchairs at 123 dollars 0.048, 446 dollars 0.047 and 606 dollars 0.046; its chip reads 2 kept plus 3 new. A bold line states that three of the top five were out of stock and all three were removed from the response entirely. A dark code window shows the execute request with the filters line in\_stock true highlighted, and skip\_cache true. The footer prints mxp.co/d/filters-exclude and the words real query, real ranking, mixpeek.](/diagrams/filters-exclude.webp)

Filters Exclude What Ranking Would Have Shown



](/diagrams/filters-exclude)[

![A portrait diagram in two rails. The headline reads Scope decides, what can be found at all, with the subline: the same question, asked of the whole catalog and then of one category. The search bar holds the query something to keep me warm outside, annotated: the query names no category. Rail A, badged whole catalog with the note semantic reach across every category, shows five photos in rank order: a lit tent at night for 543 dollars at 0.062, a snowy forest scene for 564 dollars at 0.060, a steaming pot on a stove for 444 dollars at 0.059, boots on a textured rug for 203 dollars at 0.052, and a tent under a starry sky for 100 dollars at 0.048; the second, third and fourth are greyed and stamped dropped, and the chip reads 5 of 5. Rail B, badged scoped with category equals tent and the note only one category can answer, shows the two surviving tents followed by three more tents at 592 dollars 0.046, 73 dollars 0.039 and 554 dollars 0.029; its chip reads 2 kept plus 3 new. A bold line states that unscoped, the index answered with tents, backpacks, rugs and pans, and that scope is a decision about what is allowed to be right. A code window shows the execute request with the filters line category tent highlighted. The footer prints mxp.co/d/scope-changes-candidates.](/diagrams/scope-changes-candidates.webp)

Scope Decides What Can Be Found at All



](/diagrams/scope-changes-candidates)[

![A portrait diagram in two rails. The headline reads A price ceiling, is not a price sort, with the subline: a price ceiling removes the expensive matches, it does not promote the cheap ones by price. The search bar holds the query premium floor lamp, annotated: premium is a word, not a number. Rail A, badged no ceiling with the note best matches, any price, shows five photos in rank order: floor lamps at 729 dollars 0.097, 299 dollars 0.093, 908 dollars 0.092 and 322 dollars 0.089, then an armchair at 451 dollars 0.086; four are greyed and stamped dropped, only the 299 dollar lamp survives, and the chip reads 5 of 5. Rail B, badged pre\_filter with price less than 300 and the note best matches under the ceiling, shows the 299 dollar lamp first at 0.093, then lamps at 230 dollars 0.071, 104 dollars 0.068, 129 dollars 0.063 and 38 dollars 0.059; its chip reads 1 kept plus 4 new. A bold line states that rank order inside the filter is still semantic, so the cheapest item lands fourth. A code window shows the execute request with the filters line price lt 300 highlighted. The footer prints mxp.co/d/numeric-filter-reranks.](/diagrams/numeric-filter-reranks.webp)

A Price Ceiling Cuts the Set and Leaves the Order Semantic



](/diagrams/numeric-filter-reranks)