An inverted index

I collect classic mystery novels, traditional British detective tales. These quaint, almost a century old puzzles have a soothing effect on me.

I do maintain a text file catalogue though (arrgh… no database for such a simple thing; a text file would do). The database I have is a csv file with the author surnames and then the book titles. Now, what if I want to reread a book again but can't remember its full name or the author name? In such a scenario, we would use an inverted index to find the complete name.

An inverted index is when you remember a word in the title and seem to look up the author's name. The following Java program prints the inverted index for a few of these books:

class AuthorAndTitle {  // 1
 private final String ...

Get Scala Functional Programming Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.