A search engine of your own: index, rank, query

The index board of the small database. A search engine is the same idea with the arrow turned around: it points from a word to the pages that hold it.
A train ticket app has a help page with a search box. A user types refund cancelled ticket. The first result is a page called “Ticket help”, which says ticket seven times and nothing about refunds. The page that explains refunds is third. The user gives up and phones support.
The search found every page that holds one of the three words. It put them in the wrong order. Putting pages in the right order is called ranking, and it is the real work in search.
By the end you will be able to build a small search engine in Python: it cuts text into tokens, stores an inverted index, ranks with TF-IDF and BM25, reads queries with plus, minus and quotes, and measures whether a new ranking beat the old one.
The history (optional)
In 1972, Karen Spärck Jones published “A statistical interpretation of term specificity and its application in retrieval” in the Journal of Documentation, volume 28, issue 1, pages 11 to 21. Its idea, later called inverse document frequency, is to judge a word by how many documents contain it. On 8 April 2016, Apache Lucene 6.0.0 was released, and its default scoring in IndexSearcher changed to BM25. Solr 6.0.0 came out the same day, with BM25 as the default for fields with no setting.
Before you start. Capstone: Database, Everything ended with a database that finds one key fast, because a small index kept apart from the data says where the key lives. Database 02: The Index built that index, a map from a key to a place in the file. Database 07: The Query Layer showed a typed request being read and turned into a plan before anything is searched. Here the key is a word.