为什么我从请求中收到的响应没有正确筛选



你好,

我正在尝试将API集成到Wordpress站点中。

API文件

我已经用Postman测试了API,并且我能够得到正确的响应。

通过阅读文档和各种其他来源,我想出了以下代码来列出各种结果,然后对结果进行搜索。

public function search_jobs( $param = [], $filter = [] ){
$update_token                   = [];
$this->id_token                 = $this->settings_obj->get_setting( 'id_token' );

$response_arr                   = [];
$response_arr['code']           = 0;
$response_arr['alert']          = "";
$response_arr['data']           = [];
$endpoint                       = $this->base_url . "job/search/fl=id,job_title,location,created_date,industry,public_description,summary;sort=published_date desc";
if( $filter && !empty( $filter ) ){
$search_string = isset( $filter['vj_search'] ) ? sanitize_text_field( $filter['vj_search'] ) : "";
$search_industry = isset( $filter['industry'] ) ? $filter['industry'] : [];
$search_location = isset( $filter['location'] ) ? $filter['location'] : [];
$search_function = isset( $filter['function'] ) ? $filter['function'] : [];
$search_filter_qry = [];
$search_filter_qry[] = "fq=private_job:0";
if( $search_industry && !empty( $search_industry ) ){
$search_filter_qry[] = "fq=sub_industry_id:" . implode( " OR ", $search_industry );
}
if( $search_location && !empty( $search_location ) ){
$search_filter_qry[] = "fq=country_code:" . implode( " OR ", $search_location );
}
if( $search_function && !empty( $search_function ) ){
$search_filter_qry[] = "fq=sfe_id:" . implode( " OR ", $search_function );
}
$search_filter_qry_str = implode( "%23&", $search_filter_qry );
if( !empty( $search_filter_qry_str ) ){
$endpoint = $endpoint . "?" . $search_filter_qry_str . "%23";
}
if( !empty( $search_string ) ){
$endpoint = $endpoint . "&q=text:" . $search_string . "%23";
}

我能够在所需页面上获得响应,也能够按位置和行业进行搜索,但我有以下问题

结果包括我试图只获得非私有$search_filter_qry[] = "fq=private_job:0";的作业的所有结果

如果我编辑$endpoint并将其更改为:

$endpoint                       = $this->base_url . "job/search/fl=id,job_title,location,created_date,industry,public_description,summary;sort=published_date desc?fq=private_job:0 %23";

我在最初显示的作业中得到了正确的响应,只有公开的结果,但随后我无法执行任何搜索。

我知道这是因为当我编辑$endpoint时,is创建了错误的请求,并且它返回了0个找到的结果。

我在这方面花了几天时间,例如通过添加?将$search_filter_qry[] = "fq=private_job:0";更改为$search_filter_qry[] = "?fq=private_job:0";?。老实说,我对API使用的SOLR Backend还不满意。

有谁能重新看看我的代码,并告诉我我缺少了什么吗。

我能够找到如下解决方案:

我将if语句之前的$endpoint更改为:

$endpoint                       = $this->base_url . "job/search/fl=id,job_title,location,created_date,industry,public_description,summary;sort=published_date desc?fq=private_job:0%23";

然后在初始if statement之后,

if( $filter && !empty( $filter ) ){

我添加了$endpoint作为

$endpoint                       = $this->base_url . "job/search/fl=id,job_title,location,created_date,industry,public_description,summary;sort=published_date desc";

这使得在搜索参数不为空的情况下连接能够正确工作。

相关内容

  • 没有找到相关文章

最新更新