Function to retrieve query occurances