快速入門:搜尋 (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)

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: %w", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %w", 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: %w", query, err)
	}

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

	return resp, nil
}

根據特定欄位取得職缺數量的直方圖

搜尋 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)

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: %w", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %w", 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: %w", err)
	}

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

	return resp, nil
}

在這個案例中,我們要取得系統中跨不同商情項目 (CATEGORY 和 CITY) 並符合指定篩選器的所有職缺的計數。

自動完成 API 會根據求職者輸入的內容,提供求職者可能會有興趣的職稱或公司名稱建議。請在 UI 的搜尋列使用這個 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)

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: %w", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %w", 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: %w", query, companyName, err)
	}

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

	return resp, nil
}

設定職缺數據分析架構,使用用戶端事件來微調 Cloud Talent Solution

您現在已準備好將網站的搜尋結果最佳化 (請參閱使用用戶端事件改善搜尋結果準確度)。 為提升求職者的搜尋結果準確度,將搜尋結果最佳化是非常重要的步驟。