通勤に関する検索(v3)

求人検索リクエストに通勤時間フィルタを追加すると、出発地からの移動時間が指定範囲内にある求人のみを取得できます。 結果には、条件に一致した求人の推定通勤時間(秒)が含まれます。

特定の通勤時間内の求人を返すには、JobQuery.commuteFilter フィールドに CommuteFilter オブジェクトを指定して、jobs.search リクエストを送信します。求人の通勤時間を計算するために、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 クライアント ライブラリをご覧ください。

# 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

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
}

必須項目

  • commuteMethod: 通勤時間を計算する際に使用する交通手段。DRIVINGTRANSIT を指定できます。V3p1beta1 以降のすべてのバージョンでは、交通手段に WALKINGCYCLING も指定できます。徒歩通勤や自転車通勤の経路には、工事などの実際の状況が反映されていない場合や、明確な歩道や自転車専用道路が含まれていない場合があります。こうしたレスポンスによって返される結果には warnings が含まれており、その旨をユーザーに表示する必要があります。

  • travelDuration: 最大移動時間(秒)。最大許容値は 3600s(1 時間)です。123s の形式で指定します。

  • startCoordinates: 通勤時間の計算で出発地として使用する場所の緯度と経度。LatLng オブジェクトを使用します。

省略可能項目

  • allowImpreciseAddresses: 「正確」な住所は、番地レベルの住所または GPS 座標として定義されます。allowImpreciseAddressestrue に設定されている場合、「不正確」な住所(市区町村、都道府県、または国のみ)が指定された求人も返されることがあります。市区町村以上のレベルの住所では、テキスト マッチングが使用されます。 このフィールドを false に設定するか、指定していない場合は、正確な住所を含む求人だけが、通勤に関する検索から返されます。
  • roadTraffic: 通勤時間の計算に使用する混雑度を指定します。TRAFFIC_FREEBUSY_HOUR を指定できます。departureHourLocal が指定されている場合は、使用できません。

  • departureTime: 渋滞状況の計算で使用する出発時間。startLocation のタイムゾーンでの時間を表す 0~23 の整数を使用できます。roadTraffic が指定されている場合は、使用できません。