Adding code for per query score calculation