【发布时间】:2018-10-13 08:01:37
【问题描述】:
我有这个示例 PHP 代码:
public function getListFromAzure($searchParam, $listCategory, $request){
$aListingManager = $this->get('recruitday.model_manager.job_listing');
$url = $jobListingManager->getAzureSearchParam($request, 'azure_search_idx');
$apiKey = $jobListingManager->getAzureSearchParam($request, 'azure_key');
$searchParam = preg_replace('/\s+/', '+', $searchParam);
$postdata = json_encode(
array(
'search' => $searchParam,
'filter' => $listCategory,
'orderby'=> 'publishedDate desc',
'facets' => array('locationName','empType', 'workSchedule','listFunction','positionLevel','industry'),
'top' => 15,
)
);
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Content-type: application/json\r\n" .
"api-key: ". $apiKey . "\r\n" .
"Accept: application/json",
'content'=>$postdata
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents($url, false, $context);
$file = json_decode($file,true);
return $file;
}
这在单个查询/页面上运行良好。 假设我有 10,000 条记录要提取,并且在单个查询中,Azure 搜索的记录限制为 1000 条。 这应该提供 azure 搜索参数 $top- 它指定要在批处理中返回多少项目,而 $skip 指定要跳过多少项目。 插入这部分代码:
$postdata = json_encode(
array(
'search' => $searchParam,
'filter' => $jobCategory,
'orderby'=> 'publishedDate desc',
'facets' => array('locationName','employmentType', 'workSchedule','jobFunction','positionLevel','industry'),
'top' => 15,
'skip' => 0,
'count' => true
)
);
假设,此查询将针对第一批/页面作为 top = 15 条记录显示。 对于下一批/页面跳过将迭代例如 'skip' => 15.
问题是我不知道如何迭代这个参数。还是我应该迭代这个?还是有其他方法? 天蓝色搜索参数参考:https://docs.microsoft.com/en-us/azure/search/search-pagination-page-layout
我正在考虑附加 json 文件。相关搜索:Append data to a .JSON file with PHP
以前,我显示了 1000 条记录。但我需要调整,因为我的记录已经有 1000 多条记录。 在前端——我通过 ajax 调用它。然后形成html。 然后我通过 jquery/javascript 将分页调整为每页(例如)20 条记录的块。
希望我不会混淆任何人。先感谢您!干杯!
顺便说一句:我正在使用 PHP,Symfony 2。
【问题讨论】:
标签: php ajax azure azure-cognitive-search