Title and body, with a boost of 3
BM25 is computed separately over the titles and over the bodies of six handbook passages (so the numbers differ from the twelve-passage ones in Topic 1.4).
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
helmet body: D4=1.660 title: none combined: D4=1.660
damage body: none title: D5=1.784 combined: D5=5.351
refunds body: none title: D1=1.784 combined: D1=5.351
late body: D6=1.578 title: D6=1.356 combined: D6=5.645
monthly pass body: D8=3.237 title: D8=2.711 combined: D8=11.370