implement index & query in scala.