original_string: public function findDistance(Query $query, array $options) {
  		$options += ['tableName' => null, 'sort' => true];
  		$sql = $this->distanceExpr($options['lat'], $options['lng'], null, null, $options['tableName']);
  
  		if ($query->autoFields() === null) {
  			$query->autoFields(true);
  		}
  
  		$query->select(['distance' => $query->newExpr($sql)]);
  		if (isset($options['distance'])) {
  			// Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
  			$query->where(function ($exp) use ($sql, $options) {
  				return $exp->lt($sql, $options['distance']);
  			});
  		}
  
  		if ($options['sort']) {
  			$sort = $options['sort'] === true ? 'ASC' : $options['sort'];
  			$query->order(['distance' => $sort]);
  		}
  
  		return $query;
  	}
code: public function findDistance(Query $query, array $options) {
  		$options += ['tableName' => null, 'sort' => true];
  		$sql = $this->distanceExpr($options['lat'], $options['lng'], null, null, $options['tableName']);
  
  		if ($query->autoFields() === null) {
  			$query->autoFields(true);
  		}
  
  		$query->select(['distance' => $query->newExpr($sql)]);
  		if (isset($options['distance'])) {
  			// Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
  			$query->where(function ($exp) use ($sql, $options) {
  				return $exp->lt($sql, $options['distance']);
  			});
  		}
  
  		if ($options['sort']) {
  			$sort = $options['sort'] === true ? 'ASC' : $options['sort'];
  			$query->order(['distance' => $sort]);
  		}
  
  		return $query;
  	}
code_tokens: public function findDistance ( Query $ query , array $ options ) { $ options += [ 'tableName' => null , 'sort' => true ] ; $ sql = $ this -> distanceExpr ( $ options [ 'lat' ] , $ options [ 'lng' ] , null , null , $ options [ 'tableName' ] ) ; if ( $ query -> autoFields ( ) === null ) { $ query -> autoFields ( true ) ; } $ query -> select ( [ 'distance' => $ query -> newExpr ( $ sql ) ] ) ; if ( isset ( $ options [ 'distance' ] ) ) { // Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet $ query -> where ( function ( $ exp ) use ( $ sql , $ options ) { return $ exp -> lt ( $ sql , $ options [ 'distance' ] ) ; } ) ; } if ( $ options [ 'sort' ] ) { $ sort = $ options [ 'sort' ] === true ? 'ASC' : $ options [ 'sort' ] ; $ query -> order ( [ 'distance' => $ sort ] ) ; } return $ query ; }
docstring: Custom finder for distance.
  
  Options:
  - lat (required)
  - lng (required)
  - tableName
  - distance
  - sort
  
  @param \Cake\ORM\Query $query Query.
  @param array $options Array of options as described above
  @return \Cake\ORM\Query
docstring_tokens: Custom finder for distance .