如何使用Elasticsearch来;随机化;PHP中的搜索结果?
我试图使用Elasticsearch的功能评分,但也邀请了其他方法 我现有的搜索结果如下所示:如何使用Elasticsearch来;随机化;PHP中的搜索结果?,php,search,random,
elasticsearch,Php,Search,Random,
elasticsearch,我试图使用Elasticsearch的功能评分,但也邀请了其他方法 我现有的搜索结果如下所示: $searchParams['body']['query']['filtered']['query']["match_all"] = array("boost" => 1); 如何将函数\ U分数添加到此搜索?这是我现在拥有的 $randomScore = new \stdClass(); // will be date or userid in the future $randomScore
$searchParams['body']['query']['filtered']['query']["match_all"] = array("boost" => 1);
如何将函数\ U分数添加到此搜索?这是我现在拥有的
$randomScore = new \stdClass();
// will be date or userid in the future
$randomScore->seed = 5;
$functionScore = array(
array("random_score" => $randomScore)
);
$searchParams['body']['query']['function_score']['functions'] = $functionScore;
$queryResponse = $client->search($searchParams);
这似乎非常接近正确。我只是需要更多的脑力。你需要做两件事:
$params = array();
$params['body']['size'] = 10;
$params['body']['from'] = 0;
$random = new \stdClass();
$random->seed = time(); //change this to make randomization consistent, e.g. user id
$params['body']['query']['function_score']['functions'][]['random_score'] = $random;
$params['body']['query']['function_score']['query']['bool']['must_not'] = array(
'term' => array(
'_id' => $this->get('currentPageId'),
)
);
$params['body']['query']['function_score']['query']['bool']['must'] = array(
'term' => array(
'isAlias' => false
)
);