通勤に関する検索(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 クライアント ライブラリをご覧ください。

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
}

必須項目

  • 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 が指定されている場合は、使用できません。