public addDecayFunction ( string $function, string $field, string $origin, string $scale, string $offset = null, float $decay = null, float $weight = null, AbstractQuery $filter = null, string $multiValueMode = null ) | ||
$function | string | see DECAY_* constants for valid options |
$field | string | the document field on which to perform the decay function |
$origin | string | the origin value for this decay function |
$scale | string | a scale to define the rate of decay for this function |
$offset | string | If defined, this function will only be computed for documents with a distance from the origin greater than this value |
$decay | float | optionally defines how documents are scored at the distance given by the $scale parameter |
$weight | float | optional factor by which to multiply the score at the value provided by the $scale parameter |
$filter | AbstractQuery | a filter associated with this function |
$multiValueMode | string | see MULTI_VALUE_MODE_* constants for valid options |
public function addDecayFunction($function, $field, $origin, $scale, $offset = null, $decay = null, $weight = null, AbstractQuery $filter = null, $multiValueMode = null)
{
$functionParams = [$field => ['origin' => $origin, 'scale' => $scale]];
if (!is_null($offset)) {
$functionParams[$field]['offset'] = $offset;
}
if (!is_null($decay)) {
$functionParams[$field]['decay'] = (double) $decay;
}
if (null !== $multiValueMode) {
$functionParams['multi_value_mode'] = $multiValueMode;
}
return $this->addFunction($function, $functionParams, $filter, $weight);
}
public function testGauss() { $query = new FunctionScore(); $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'location', $this->locationOrigin, "4mi"); $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'price', 0, 10); $response = $this->type->search($query); $results = $response->getResults(); // the document with the closest location and lowest price should be scored highest $result0 = $results[0]->getData(); $this->assertEquals("Mr. Frostie's", $result0['name']); }