通勤時間搜尋 (v3)

職缺搜尋要求可以包括通勤時間篩選器,限制系統只能傳回從出發地點開始計算,通勤時間在特定範圍內的職缺。搜尋結果會包括符合條件的職缺的預估通勤時間,以秒為單位。

如要傳回特定通勤時間內的職缺,請傳送 jobs.search 要求,並在 JobQuery.commuteFilter 欄位中加入 CommuteFilter 物件。Cloud Talent Solution 會根據職缺的地址來計算該職缺所需的通勤時間。如果沒有詳細的地址,Cloud Talent Solution 會嘗試推論出該職缺的實際街道地址。

Java

如要進一步瞭解如何安裝及建立 Cloud Talent Solution 用戶端,請參閱 Cloud Talent Solution 用戶端程式庫


public static void commuteSearch(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");
  JobQuery jobQuery =
      new JobQuery()
          .setCommuteFilter(
              new CommuteFilter()
                  .setRoadTraffic("TRAFFIC_FREE")
                  .setCommuteMethod("TRANSIT")
                  .setTravelDuration("1000s")
                  .setStartCoordinates(
                      new LatLng().setLatitude(37.422408).setLongitude(-122.085609)));
  if (companyName != null) {
    jobQuery.setCompanyNames(Arrays.asList(companyName));
  }

  SearchJobsRequest searchJobsRequest =
      new SearchJobsRequest()
          .setJobQuery(jobQuery)
          .setRequestMetadata(requestMetadata)
          .setJobView("JOB_VIEW_FULL")
          .setRequirePreciseResultSize(true);
  SearchJobsResponse response =
      talentSolutionClient
          .projects()
          .jobs()
          .search(DEFAULT_PROJECT_ID, searchJobsRequest)
          .execute();
  Thread.sleep(1000);
  System.out.printf("Search jobs for commute results: %s\n", response);
}

Python

如要進一步瞭解如何安裝及建立 Cloud Talent Solution 用戶端,請參閱 Cloud Talent Solution 用戶端程式庫

def commute_search(client_service, company_name):
    request_metadata = {
        "user_id": "HashedUserId",
        "session_id": "HashedSessionId",
        "domain": "www.google.com",
    }
    start_location = {"latitude": 37.422408, "longitude": -122.085609}
    commute_preference = {
        "road_traffic": "TRAFFIC_FREE",
        "commute_method": "TRANSIT",
        "travel_duration": "1000s",
        "start_coordinates": start_location,
    }
    job_query = {"commute_filter": commute_preference}
    if company_name is not None:
        job_query.update({"company_names": [company_name]})
    request = {
        "job_query": job_query,
        "request_metadata": request_metadata,
        "job_view": "JOB_VIEW_FULL",
        "require_precise_result_size": True,
    }
    response = (
        client_service.projects().jobs().search(parent=parent, body=request).execute()
    )
    print(response)

Go

如要進一步瞭解如何安裝及建立 Cloud Talent Solution 用戶端,請參閱 Cloud Talent Solution 用戶端程式庫


// commuteSearch searches for jobs within commute filter.
func commuteSearch(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)
	}

	jobQuery := &talent.JobQuery{
		CommuteFilter: &talent.CommuteFilter{
			RoadTraffic:    "TRAFFIC_FREE",
			CommuteMethod:  "TRANSIT",
			TravelDuration: "1000s",
			StartCoordinates: &talent.LatLng{
				Latitude:  37.422408,
				Longitude: -122.085609,
			},
		},
	}
	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",
		RequirePreciseResultSize: true,
	}
	resp, err := service.Projects.Jobs.Search(parent, req).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to search for jobs with commute filter: %w", err)
	}
	return resp, nil
}

Ruby

如要進一步瞭解如何安裝及建立 Cloud Talent Solution 用戶端,請參閱 Cloud Talent Solution 用戶端程式庫

# project_id              = "Id of the project"
# commute_method          = "The method of transportation for which to calculate the commute time"
# travel_duration         = "The maximum travel time in seconds"
# start_coordinates       = "The latitude and longitude of the location from which to calculate the commute time"

require "google/apis/jobs_v3"

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"
# Set location filter
commute_filter = jobs::CommuteFilter.new road_traffic:      "TRAFFIC_FREE",
                                         commute_method:    commute_method,
                                         travel_duration:   travel_duration,
                                         start_coordinates: start_coordinates
# Perform a search for analyst  related jobs
search_jobs_request =
  jobs::SearchJobsRequest.new request_metadata:            request_metadata,
                              job_query:                   (jobs::JobQuery.new commute_filter: commute_filter),
                              job_view:                    "JOB_VIEW_FULL",
                              require_precise_result_size: true
search_jobs_response = talent_solution_client.search_jobs project_id, search_jobs_request
puts search_jobs_response.to_json
search_jobs_response

必填欄位

  • commuteMethod:交通方式,用來計算通勤時間。選項為 DRIVINGTRANSIT。 V3p1beta1 以後的所有版本也會包含 WALKINGCYCLING 大眾運輸模式。 步行和單車路線可能無法反映施工等實際情況,也可能不包含清楚的步道或單車道。這些回應將會在傳回的結果中包含 warnings,而您必須向使用者顯示這些警告。

  • travelDuration:通勤時間上限,以秒為單位。系統允許的最大值為 3600s (也就是一小時),格式為 123s

  • startCoordinates:出發地點的緯度和經度,用來計算通勤時間。接受 LatLng 物件。

選填欄位

  • allowImpreciseAddresses:「精確」地址定義為街道層級或 GPS 座標。如果將 allowImpreciseAddresses 設為 true,可能會傳回地址「不精確」(只有城市、州/省或國家/地區) 的職缺。如為城市層級或更粗略的地址,服務會採用文字比對。如果將這個欄位設為 false,或是不指定這個欄位,通勤時間搜尋只會傳回包含精確地址的職缺。
  • roadTraffic:指定用來計算通勤時間的交通密度。選項為 TRAFFIC_FREEBUSY_HOUR。如果已指定 departureHourLocal,則不得使用這個欄位。

  • departureTime:出發時間,用來計算交通影響程度。 系統接受介於 0 至 23 的整數,代表 startLocation 所在時區的時間。如果指定了 roadTraffic,就不能使用這個欄位。