code: private void search(double[] q, Node node, Neighbor<double[], E> neighbor) {
          if (node.isLeaf()) {
              // look at all the instances in this leaf
              for (int idx = node.index; idx < node.index + node.count; idx++) {
                  if (q == keys[index[idx]] && identicalExcluded) {
                      continue;
                  }
  
                  double distance = Math.squaredDistance(q, keys[index[idx]]);
                  if (distance < neighbor.distance) {
                      neighbor.key = keys[index[idx]];
                      neighbor.value = data[index[idx]];
                      neighbor.index = index[idx];
                      neighbor.distance = distance;
                  }
              }
          } else {
              Node nearer, further;
              double diff = q[node.split] - node.cutoff;
              if (diff < 0) {
                  nearer = node.lower;
                  further = node.upper;
              } else {
                  nearer = node.upper;
                  further = node.lower;
              }
  
              search(q, nearer, neighbor);
  
              // now look in further half
              if (neighbor.distance >= diff * diff) {
                  search(q, further, neighbor);
              }
          }
      }
docs: Returns the nearest neighbors of the given target starting from the give
  tree node.
  
  @param q    the query key.
  @param node the root of subtree.
  @param neighbor the current nearest neighbor.