快速入门:搜索 (v3)

利用 Cloud Talent Solution,您可以在 Google Cloud Talent Solution 中搜索已发布到我们系统的当前有效职位。本教程将为您提供搜索在创建公司和招聘信息中创建的招聘信息的简便方法。

如果您能够发出搜索请求,请务必实施招聘信息分析框架(请参阅改进预训练模型。 这是 Cloud Talent Solution 价值的核心,并直接影响改进的搜索结果。

搜索职位信息贴

搜索在创建公司和职位教程中创建的职位。 Cloud Talent Solution 还使用 RequestMetadata 主动确保求职者在搜索招聘信息时获得一致的用户体验。务必确保正确设置此字段。请参考 RequestMetadata 文档。

Java

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


/** Simple search jobs with keyword. */
public static void basicSearcJobs(String companyName, String query)
    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");

  // Perform a search for analyst  related jobs
  JobQuery jobQuery = new JobQuery().setQuery(query);
  if (companyName != null) {
    jobQuery.setCompanyNames(Arrays.asList(companyName));
  }

  SearchJobsRequest searchJobsRequest =
      new SearchJobsRequest()
          .setRequestMetadata(requestMetadata)
          .setJobQuery(jobQuery) // Set the actual search term as defined in the jobQurey
          .setSearchMode("JOB_SEARCH"); // Set the search mode to a regular search

  SearchJobsResponse searchJobsResponse =
      talentSolutionClient
          .projects()
          .jobs()
          .search(DEFAULT_PROJECT_ID, searchJobsRequest)
          .execute();
  Thread.sleep(1000);
  System.out.printf("Simple search jobs results: %s\n", searchJobsResponse);
}

Python

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

def basic_keyword_search(client_service, company_name, keyword):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    job_query = {'query': keyword}
    if company_name is not None:
        job_query.update({'company_names': [company_name]})
    request = {
        'search_mode': 'JOB_SEARCH',
        'request_metadata': request_metadata,
        'job_query': job_query,
    }

    response = client_service.projects().jobs().search(
        parent=parent, body=request).execute()
    print(response)

C#

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


public static void BasicSearchJobs(string companyName, string query)
{
    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"
    };

    JobQuery jobQuery = new JobQuery()
    {
        Query = query,
        CompanyNames = new List<string>
        {
            companyName
        }
    };

    SearchJobsRequest searchJobRequest = new SearchJobsRequest()
    {
        RequestMetadata = requestMetadata,
        JobQuery = jobQuery,
        SearchMode = "JOB_SEARCH"
    };

    SearchJobsResponse searchJobsResponse = jobServiceClient.Projects.Jobs.Search(searchJobRequest, parent).Execute();

    Console.WriteLine("Jobs searched: " + ToJsonString(searchJobsResponse));
}

Go

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


// basicJobSearch searches for jobs with query.
func basicJobSearch(w io.Writer, projectID, companyName, query 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)
	}

	jobQuery := &talent.JobQuery{
		Query: query,
	}
	if companyName != "" {
		jobQuery.CompanyNames = []string{companyName}
	}

	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",
		},
		// Set the actual search term as defined in the jobQuery
		JobQuery: jobQuery,
		// Set the search mode to a regular search
		SearchMode: "JOB_SEARCH",
	}
	resp, err := service.Projects.Jobs.Search(parent, req).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to search for jobs with query %q: %v", query, 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 客户端库


/**
 * Simple search jobs with keyword.
 */
const basicKeywordSearch = async (jobServiceClient, companyName, keyword) => {
  try {
    const jobQuery = {
      query: keyword,
    };

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

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

    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}""
# query           = "Specify the job criteria to match against. These include location, job categories, employment types, text queries, companies, etc"

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:     "www.google.com"

# Perform a search for analyst  related jobs
job_query = jobs::JobQuery.new query: query
job_query.company_names = [company_name] unless company_name.nil?
search_jobs_request = jobs::SearchJobsRequest.new request_metadata: request_metadata,
                                                  job_query:        job_query,
                                                  search_mode:      "JOB_SEARCH"
search_jobs_response = talent_solution_client.search_jobs project_id, search_jobs_request
puts search_jobs_response.to_json
search_jobs_response

获取按特定字段统计的招聘信息数直方图

搜索 API 还会返回在 Cloud Talent Solution 中编制索引的、与搜索查询过滤器匹配的所有相关职位的直方图。现在您已经获得搜索结果,可以按不同属性统计招聘信息计数。 利用直方图 API 获取按特定属性统计的招聘信息计数。

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

这种情况下,我们将获得系统中指定过滤器中接受的、涵盖各种属性(类别和城市)的所有招聘信息的计数。

使用自动填充 API 获取建议的职务

完整的 API 会根据求职者已经输入的内容,建议他们可能感兴趣的职务或公司名称。使用此选项可在界面的搜索栏中自动填充可能的结果。

Java

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


/** Auto completes job titles within given companyName. */
public static void jobTitleAutoComplete(String companyName, String query) throws IOException {

  Complete complete =
      talentSolutionClient
          .projects()
          .complete(DEFAULT_PROJECT_ID)
          .setQuery(query)
          .setLanguageCode("en-US")
          .setType("JOB_TITLE")
          .setPageSize(10);
  if (companyName != null) {
    complete.setCompanyName(companyName);
  }

  CompleteQueryResponse results = complete.execute();

  System.out.println(results);
}

Python

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

def job_title_auto_complete(client_service, query, company_name):
    complete = client_service.projects().complete(
        name=name, query=query,
        languageCode='en-US', type='JOB_TITLE', pageSize=10)
    if company_name is not None:
        complete.companyName = company_name

    results = complete.execute()
    print(results)

C#

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


public static void JobTitleAutoComplete(String companyName, String query)
{
    CompleteRequest completeRequest = new CompleteRequest(jobServiceClient, parent)
    {
        Query = query,
        LanguageCode = "en-US",
        Type = CompleteRequest.TypeEnum.JOBTITLE,
        PageSize = 10
    };

    if (companyName != null)
    {
        completeRequest.CompanyName = companyName;
    }

    CompleteQueryResponse results = completeRequest.Execute();
    Console.WriteLine("Completion results: " + ToJsonString(results));
}

Go

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


// jobTitleAutoComplete suggests the job titles of the given companyName based
// on query.
func jobTitleAutoComplete(w io.Writer, projectID, companyName, query string) (*talent.CompleteQueryResponse, 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
	complete := service.Projects.Complete(parent).Query(query).LanguageCode("en-US").Type("JOB_TITLE").PageSize(10)
	if companyName != "" {
		complete.CompanyName(companyName)
	}
	resp, err := complete.Do()
	if err != nil {
		return nil, fmt.Errorf("failed to auto complete with query %s in company %s: %v", query, companyName, err)
	}

	fmt.Fprintf(w, "Auto complete results:")
	for _, c := range resp.CompletionResults {
		fmt.Fprintf(w, "\t%v", c.Suggestion)
	}

	return resp, nil
}

Node.js

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


/**
 * Auto completes job titles within given companyName.
 */
const jobTitleAutoComplete = async (jobServiceClient, query, companyName) => {
  try {
    const request = {
      name: `projects/${PROJECT_ID}`,
      query: query,
      languageCode: 'en-US',
      type: 'JOB_TITLE',
      pageSize: 10,
    };

    if (companyName) {
      request.companyName = companyName;
    }

    const complete = await jobServiceClient.projects.complete(request);

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

Ruby

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

# project_id     = "Project id required"
# company_name   = "The resource name of the company listing the job. The format is "projects/{project_id}/companies/{company_id}""
# query          = "Job title prefix as auto complete query"

require "google/apis/jobs_v3"

jobs = Google::Apis::JobsV3
talent_solution_client = jobs::CloudTalentSolutionService.new
talent_solution_client.authorization = Google::Auth.get_application_default(
  "https://www.googleapis.com/auth/jobs"
)

page_size = 10
type = "JOB_TITLE"
language_code = "en-US"
result = talent_solution_client.complete_project(
  project_id, company_name: company_name, page_size: page_size, query: query,
    language_code: language_code, type: type
) do |result, err|
  if err.nil?
    puts "Job title auto complete result: #{result.to_json}"
  else
    puts "Error when auto completing job title. Error message: #{err.to_json}"
  end
end
result

设置职位分析框架,利用客户活动调整 Cloud Talent Solution

您现在可以优化站点的搜索结果(请参阅使用客户端事件改进搜索结果)。 优化搜索结果是为求职者改进结果的关键步骤。