complete invertedIndex function