Chunks of code for calculating cosine similarity between documents stored in Lucene index.