'how to print out a forward index in whoosh?

I am looking on a way to display the forward index using the whoosh library in python. Suppose we have an index and we want to display like that:

Doc Postings
1   [(text=apple, freq=2)]
2   [(text=apple, freq=5), (text='bear', freq=7)]
3   [(text=apple, freq=1)]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source