O'Reilly logo

Scala Functional Programming Patterns by Atul S. Khot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required