脚本分数功能不起作用但addDecayFunction正在运行FunctionScore查询

时间:2014-08-06 09:45:13

标签: search elasticsearch elastica

我正在使用Elastica并将使用\ Elastica \ Query \ FunctionScore(); function score - > script_score 即可。这里addDecayFunction()很好,但addScriptScoreFunction()不起作用而且没有任何异常。

DecyFunction被评论,因为它正在运作

这是代码

$scriptString = "doc['geo_location'].distanceInMiles('42.946697', '-76.113623')";
$script = new \Elastica\Script($scriptString);
$query = new \Elastica\Query\FunctionScore();

$query->addScriptScoreFunction($script);

// $locationOrigin = "32.804654, -117.242594";  
// $locationScale = '2mi';
// $query->addDecayFunction(\Elastica\Query\FunctionScore::DECAY_GAUSS, 'geo_location', $locationOrigin, $locationScale);

$resultSet = $type->search($query); 
$results = $resultSet->getResults();

$totalResults = $resultSet->getTotalHits();

if ( $totalResults > 0 ) {


    echo "<b>Total Results Found are:</b> " . $totalResults . "<br>";
    foreach ( $results as $result ) {

        echo $result->getScore();   
        $data = $result->getData();
        var_dump($data);
    }

}

1 个答案:

答案 0 :(得分:1)

也许你忘了启用脚本?

script.disable_dynamic: false