Just Build it...

../home

../projects

../archive

../ about

../ writings

Inverted Index

2025-06-22

Inverted Index implementation in Go

A toy implementation of Inverted Index in go, that powers most if not all the Information Retrieval for web engine, Elasticsearch, and more.

Example

Doc 1

I did enact Julius Caesar: I was killed i’ the Capiot; Brutus killed me.

Doc 2

So let it be with Caesar. The noble Brutus hath told you Caesar was ambitious.

termdocID
I1
did1
enact1
julius1
caesar1
I1
was1
killed1
i’1
the1
capitol1
brutus1
killed1
me1
so2
let2
it2
be2
with2
caesar2
the2
noble2
brutus2
hath2
told2
you2
caesar2
was2
ambitious2

Sorted :

termdocID
ambitious2
be2
brutus1
brutus2
capitol1
caesar1
caesar2
caesar2
did1
enact1
hath1
I1
I1
i’1
it2
julius1
killed1
killed1
let2
me1
noble2
so2
the1
the2
told2
you2
was1
was2
with2

Result:

termdoc. freqpostings lists
ambitious12
be12
brutus21 -> 2
capitol11
caesar21 -> 2
did11
enact11
hath12
I11
i’11
it12
julius11
killed11
let12
me11
noble12
so12
the21 -> 2
told12
you12
was21 -> 2
with12

Process :-

Document -> Tokenizer -> Linguistic models -> Indexer