直方图 (v3)

Cloud Talent Solution 可通过直方图的形式向您显示与给定搜索关联的职位数量。直方图搜索会返回与特定查询匹配的所有职位的计数,并按请求的 searchType 细分。例如,直方图搜索可能会按照工作性质(全职、兼职等)返回加州山景城已有的职位数量。要定义直方图的维度和参数,请按照本指南中的说明执行操作。

直方图通常与搜索调用并行运行,并使用相同的 JobQueryrequestMetadata

请求

您可以通过底层 search API 获得直方图。在 search API 上设置 histogramFacets 并定义请求的过滤条件即可实现这一目的。请注意,直方图会遵循搜索查询中定义的所有过滤条件。以下示例展示了检索直方图的机制。

必填字段

  • searchTypes 是要返回计数的类别的列表。例如,指定 EMPLOYMENT_TYPE(全职或兼职等)以返回工作性质的计数。如需查看枚举的详细列表,请参阅 SearchType

可选字段

  • jobQuery 是要在此搜索中执行的招聘信息查询。如需了解详情,请参阅搜索过滤条件。本示例中未应用任何查询。

  • requestMetadata 包含发起搜索的用户的相关信息。如需了解详情,请参阅职位搜索页面的 RequestMetadata 部分。

  • enableBroadening 可放宽对搜索请求中位置和职位类别的限制,以返回更多结果。例如,如果请求指定搜索某个位置半径 20 英里内的招聘信息,则将此标志设置为 true 可以返回超出该半径范围的招聘信息。以下示例不包括扩展的结果。

示例

以下示例返回符合 COMPANY_ID 和 customAttribute someFieldName1 的招聘信息计数列表:

Java

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


/** Histogram search */
public static void histogramSearch(String companyName) throws IOException, InterruptedException {
  // 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");

  HistogramFacets histogramFacets =
      new HistogramFacets()
          .setSimpleHistogramFacets(Arrays.asList("COMPANY_ID"))
          .setCustomAttributeHistogramFacets(
              Arrays.asList(
                  new CustomAttributeHistogramRequest()
                      .setKey("someFieldName1")
                      .setStringValueHistogram(true)));

  // conducted.
  SearchJobsRequest searchJobsRequest =
      new SearchJobsRequest()
          .setRequestMetadata(requestMetadata)
          .setSearchMode("JOB_SEARCH")
          .setHistogramFacets(histogramFacets);
  if (companyName != null) {
    searchJobsRequest.setJobQuery(new JobQuery().setCompanyNames(Arrays.asList(companyName)));
  }

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

  System.out.printf("Histogram search results: %s\n", searchJobsResponse);
}

Python

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

def histogram_search(client_service, company_name):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    custom_attribute_histogram_facet = {
        'key': 'someFieldName1',
        'string_value_histogram': True
    }
    histogram_facets = {
        'simple_histogram_facets': ['COMPANY_ID'],
        'custom_attribute_histogram_facets': [custom_attribute_histogram_facet]
    }
    request = {
        'search_mode': 'JOB_SEARCH',
        'request_metadata': request_metadata,
        'histogram_facets': histogram_facets
    }
    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)

C#

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


public static void HistogramSearch(String companyName)
{
    RequestMetadata requestMetadata = new RequestMetadata()
    {
        // Make sure to hash your userID
        UserId = "HashedUserId",
        // Make sure to hash the sessionID
        SessionId = "HashedSessionId",
        // Domain of the website where the search is conducted
        Domain = "www.google.com"
    };

    HistogramFacets histogramFacets = new HistogramFacets()
    {
        SimpleHistogramFacets = new List<String>
        {
            "COMPANY_ID"
        },
        CustomAttributeHistogramFacets = new List<CustomAttributeHistogramRequest>
        {
            new CustomAttributeHistogramRequest()
            {
                Key = "someFieldName1",
                StringValueHistogram = true
            }
        }
    };

    SearchJobsRequest searchJobsRequest = new SearchJobsRequest()
    {
        RequestMetadata = requestMetadata,
        SearchMode = "JOB_SEARCH",
        HistogramFacets = histogramFacets
    };

    if (companyName != null)
    {
        searchJobsRequest.JobQuery = new JobQuery()
        {
            CompanyNames = new List<string>
            {
                companyName
            }
        };
    }

    SearchJobsResponse searchJobsResponse = jobServiceClient.Projects.Jobs.Search(searchJobsRequest, parent).Execute();
    Console.WriteLine("Histogram search: " + ToJsonString(searchJobsResponse));
}

Go

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


// histogramSearch searches for jobs with histogram facets.
func histogramSearch(w io.Writer, projectID, companyName string) (*talent.SearchJobsResponse, error) {
	ctx := context.Background()

	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		return nil, fmt.Errorf("google.DefaultClient: %v", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %v", err)
	}

	parent := "projects/" + projectID
	req := &talent.SearchJobsRequest{
		// Make sure to set the RequestMetadata the same as the associated
		// search request.
		RequestMetadata: &talent.RequestMetadata{
			// Make sure to hash your userID.
			UserId: "HashedUsrId",
			// Make sure to hash the sessionID.
			SessionId: "HashedSessionId",
			// Domain of the website where the search is conducted.
			Domain: "www.googlesample.com",
		},
		HistogramFacets: &talent.HistogramFacets{
			SimpleHistogramFacets: []string{"COMPANY_ID"},
			CustomAttributeHistogramFacets: []*talent.CustomAttributeHistogramRequest{
				{
					Key:                  "someFieldString",
					StringValueHistogram: true,
				},
			},
		},
		// Set the search mode to a regular search.
		SearchMode:               "JOB_SEARCH",
		RequirePreciseResultSize: true,
	}
	if companyName != "" {
		req.JobQuery = &talent.JobQuery{
			CompanyNames: []string{companyName},
		}
	}

	resp, err := service.Projects.Jobs.Search(parent, req).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to search for jobs with Historgram Facets: %v", err)
	}

	fmt.Fprintln(w, "Jobs:")
	for _, j := range resp.MatchingJobs {
		fmt.Fprintf(w, "\t%q\n", j.Job.Name)
	}

	return resp, nil
}

Node.js

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


/**
 * Histogram search
 */
const histogramSearch = async (jobServiceClient, companyName) => {
  try {
    const requestMetadata = {
      userId: 'HashedUserId',
      sessionId: 'HashedSessionId',
      domain: 'www.google.com',
    };

    const customAttributeHistogramFacet = {
      key: `someFieldName1`,
      stringValueHistogram: true,
    };

    const histogramFacets = {
      simpleHistogramFacets: ['COMPANY_ID'],
      customAttributeHistogramFacets: [customAttributeHistogramFacet],
    };

    const request = {
      parent: `projects/${PROJECT_ID}`,
      resource: {
        searchMode: 'JOB_SEARCH',
        requestMetadata: requestMetadata,
        histogramFacets: histogramFacets,
      },
    };

    if (companyName) {
      request.resource.jobQuery = {companyNames: [companyName]};
    }

    const result = await jobServiceClient.projects.jobs.search(request);

    console.log(JSON.stringify(result.data));
  } catch (e) {
    console.error(e);
    throw e;
  }
};

Ruby

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

  # project_id     = "Id of the project"
  # company_name   = "The resource name of the company listing the job. The format is "projects/{project_id}/companies/{company_id}""
  require "google/apis/jobs_v3"

  # Instantiate the client
  jobs = Google::Apis::JobsV3
  talent_solution_client = jobs::CloudTalentSolutionService.new
  # @see
  # https://developers.google.com/identity/protocols/application-default-credentials#callingruby
  talent_solution_client.authorization = Google::Auth.get_application_default(
    "https://www.googleapis.com/auth/jobs"
  )

  # Make sure to set the request_metadata the same as the associated search request
  request_metadata = jobs::RequestMetadata.new user_id:    "HashedUserId",
                                               session_id: "HashedSessionId",
                                               domain:     "http://careers.google.com"

  custom_attribute_histogram_request =
    jobs::CustomAttributeHistogramRequest.new key:                    "someFieldName1",
                                              string_value_histogram: true
  histogram_facets =
    jobs::HistogramFacets.new simple_histogram_facets:           ["COMPANY_ID"],
                              custom_attribute_histogram_facets: [custom_attribute_histogram_request]
  # Perform a search for analyst  related jobs
  job_query = jobs::JobQuery.new company_names: [company_name]

  search_jobs_request = jobs::SearchJobsRequest.new request_metadata: request_metadata,
                                                    job_query:        job_query,
                                                    histogram_facets: histogram_facets
  search_jobs_response = talent_solution_client.search_jobs project_id, search_jobs_request

  puts search_jobs_response.to_json
  search_jobs_response
end

相关性阈值

直方图请求不使用相关性阈值。要确保直方图搜索与相同的职位搜索之间的计数一致,职位搜索中的 disableKeywordMatch 必须为 false