Heres a related question that I came across recently which is some what related to the above problem:
Given the inverted index i.e. words mapped to positions of words, and another set of words S, find the smallest window in the file that contains all the words in the set S.
]]>