calculate the cosine and ranking