Search lines using only one database query