O'Reilly logo

Distributed Computing with Go by V.N. Nikhil Anurag

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 example – the inverted index for words in books

Let's take the data from the same example as before but now classified according to an inverted index:

* apple
  - Book 1 - 4, 10, 20
  - Book 3 - 36, 55, 74
    
* banana
  - Book 2 - 14, 19, 66
    
* cake
  - Book 2 - 10, 37, 45
  - Book 3 - 1, 9, 77
    
* cat
  - Book 1 - 10, 21, 22
    
* whale
  - Book 3 - 11, 59, 79
 
* zebra
  - Book 1 - 15, 25, 63
  - Book 2 - 67, 100, 129  

With this setup, we can efficiently answer following questions:

  • Does a word exist in the index?
  • What are all the books a word exists in?
  • What pages does a word occur on in a given book?

Let's again try to find three words from the inverted index:

  • apple
  • banana
  • parrot
* Searching for 'apple'
 - Scanning Inverted Index. Result: Found a list ...

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