Add a decay function to the query.
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 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']); }
/** * @group functional */ public function testSetMinScore() { $this->_checkVersion('1.5'); $expected = array('function_score' => array('min_score' => 0.8, 'functions' => array(array('gauss' => array('price' => array('origin' => 0, 'scale' => 10)))))); $query = new FunctionScore(); $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'price', 0, 10); $returnedValue = $query->setMinScore(0.8); $this->assertEquals($expected, $query->toArray()); $this->assertInstanceOf('Elastica\\Query\\FunctionScore', $returnedValue); $response = $this->_getIndexForTest()->search($query); $results = $response->getResults(); $this->assertCount(1, $results); $this->assertEquals(1, $results[0]->getId()); }