Error codes: ranking versus exact match
Support passages E1 to E3 and H1 are made up for this example. They are not part of the handbook.
Word counts ignore order, structure and exactness. Positions let a search match a phrase, fields let a title count for more than the body, and identifiers such as error codes must be matched exactly or not at all.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write has_phrase(words, phrase) that is true when the list phrase appears as consecutive items in the list words. Test it on the words of "Later cancellations get ride credit instead." with the phrases ride credit, credit ride and get ride.
Write combined(title_score, body_score, boost=3.0) returning the boosted sum and print it for the pairs (1.356, 1.578) and (0.0, 1.66) to 3 decimals.
Explain it without notes
How does a phrase query use positions, and how does it differ from an AND query?
Why are fields and boosts useful, and what is a risk of adding the scores of two fields?
Why must identifiers be matched exactly, and what goes wrong after a one-character typo?
Expected output
ERR-4012
BM25: E1=1.182, E3=1.012, E2=0.357
exact match: E1 E3
ERR-4O12
BM25: E1=0.401, E2=0.357, E3=0.344
exact match: (none)