直方图 (v3)

您可以获得与给定搜索关联的职位数的直方图。设置了直方图属性的搜索请求会返回搜索结果以及与特定查询匹配的所有职位的计数,信息按请求的 searchType 细分。

例如,直方图搜索可能会针对客户的一组职位,按工作性质(全职、兼职等)返回职位数。

利用 Cloud Talent Solution 测试版 (v3p1beta1),您将能以更灵活、更直观的方式定义结构更简单的直方图。直方图表示法不会更改。

优点

直方图查询的新结构使得开发者能够以更直观的方式定义直方图请求,同时更清晰地阐释了分桶、范围等术语的定义。

用法

定义直方图时,搜索查询旧的结构化字段被新的直方图元素取代。

代码示例

以下代码示例返回直方图结果。

histogramQuery 字段现在是单字符串字段,是定义直方图的表达式。如需详细了解可用于直方图查询的函数,请参阅 HistogramQuery

Java

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


/**
 * New histogram search
 */
public static void newHistogramSearch(String companyName) throws IOException {
  // Make sure to set the requestMetadata the same as the associated search request
  RequestMetadata requestMetadata =
      new RequestMetadata()
          // Make sure to hash your userID
          .setUserId("HashedUserId")
          // Make sure to hash the sessionID
          .setSessionId("HashedSessionID")
          // Domain of the website where the search is conducted
          .setDomain(
              "www.google.com");

  HistogramQuery companyIdHistogramQuery = new HistogramQuery()
      .setHistogramQuery("count(company_id)");
  HistogramQuery customFieldHistogramQuery = new HistogramQuery()
      .setHistogramQuery("count(string_custom_attribute[\"someFieldName1\"])");

  // conducted.
  SearchJobsRequest searchJobsRequest =
      new SearchJobsRequest()
          .setRequestMetadata(requestMetadata)
          .setHistogramQueries(Arrays.asList(companyIdHistogramQuery, customFieldHistogramQuery));
  if (companyName != null) {
    searchJobsRequest.setJobQuery(new JobQuery().setCompanyNames(Arrays.asList(companyName)));
  }

  SearchJobsResponse searchJobsResponse =
      talentSolutionClient
          .projects()
          .jobs()
          .search(DEFAULT_PROJECT_ID, searchJobsRequest)
          .execute();

  System.out.println(searchJobsResponse);
}

Python

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

def new_histogram_search(client_service, company_name):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    company_id_histogram_query = {
        'histogram_query': 'count(company_id)'
    }
    custom_field_histogram_query = {
        'histogram_query': 'count(string_custom_attribute["someFieldName1"])'
    }
    request = {
        'search_mode': 'JOB_SEARCH',
        'request_metadata': request_metadata,
        'histogram_queries': [company_id_histogram_query, custom_field_histogram_query]
    }
    if company_name is not None:
        request.update({'job_query': {'company_names': [company_name]}})
    response = client_service.projects().jobs().search(
        parent=parent, body=request).execute()
    print(response)