K-nearest search method implementation