通勤検索

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

特定の通勤時間内の求人を返すには、JobQuery.commuteFilter フィールドに CommuteFilter オブジェクトを指定して、jobs.search リクエストを送信します。求人の通勤時間を計算するために、Cloud Talent Solution ではその求人の address を使用します。詳細な住所を指定しないと、Cloud Talent Solution では求人の実際の住所が推測されません。

Java

CTS 用のクライアント ライブラリをインストールして使用する方法については、CTS クライアント ライブラリをご覧ください。 詳細については、CTS Java API のリファレンス ドキュメントをご覧ください。

CTS への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


import com.google.cloud.talent.v4.CommuteFilter;
import com.google.cloud.talent.v4.CommuteMethod;
import com.google.cloud.talent.v4.Job;
import com.google.cloud.talent.v4.JobQuery;
import com.google.cloud.talent.v4.JobServiceClient;
import com.google.cloud.talent.v4.RequestMetadata;
import com.google.cloud.talent.v4.SearchJobsRequest;
import com.google.cloud.talent.v4.SearchJobsResponse;
import com.google.cloud.talent.v4.TenantName;
import com.google.protobuf.Duration;
import com.google.type.LatLng;
import java.io.IOException;

public class CommuteSearchJobs {

  public static void searchJobs() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String tenantId = "your-tenant-id";
    searchJobs(projectId, tenantId);
  }

  // Search Jobs with histogram queries.
  public static void searchJobs(String projectId, String tenantId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
      TenantName parent = TenantName.of(projectId, tenantId);
      String domain = "www.example.com";
      String sessionId = "Hashed session identifier";
      String userId = "Hashed user identifier";
      RequestMetadata requestMetadata =
          RequestMetadata.newBuilder()
              .setDomain(domain)
              .setSessionId(sessionId)
              .setUserId(userId)
              .build();

      CommuteMethod commuteMethod = CommuteMethod.DRIVING;
      long seconds = 3600L;
      Duration travelDuration = Duration.newBuilder().setSeconds(seconds).build();

      double latitude = 37.422408;
      double longitude = -122.084068;
      LatLng startCoordinates =
          LatLng.newBuilder().setLatitude(latitude).setLongitude(longitude).build();

      CommuteFilter commuteFilter =
          CommuteFilter.newBuilder()
              .setCommuteMethod(commuteMethod)
              .setTravelDuration(travelDuration)
              .setStartCoordinates(startCoordinates)
              .build();

      JobQuery jobQuery = JobQuery.newBuilder().setCommuteFilter(commuteFilter).build();
      SearchJobsRequest request =
          SearchJobsRequest.newBuilder()
              .setParent(parent.toString())
              .setRequestMetadata(requestMetadata)
              .setJobQuery(jobQuery)
              .build();

      for (SearchJobsResponse.MatchingJob responseItem :
          jobServiceClient.searchJobs(request).getMatchingJobsList()) {
        System.out.format("Job summary: %s%n", responseItem.getJobSummary());
        System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
        Job job = responseItem.getJob();
        System.out.format("Job name: %s%n", job.getName());
        System.out.format("Job title: %s%n", job.getTitle());
      }
    }
  }
}

Java

CTS 用のクライアント ライブラリをインストールして使用する方法については、CTS クライアント ライブラリをご覧ください。 詳細については、CTS Java API のリファレンス ドキュメントをご覧ください。

CTS への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


import com.google.cloud.talent.v4beta1.CommuteFilter;
import com.google.cloud.talent.v4beta1.CommuteMethod;
import com.google.cloud.talent.v4beta1.Job;
import com.google.cloud.talent.v4beta1.JobQuery;
import com.google.cloud.talent.v4beta1.JobServiceClient;
import com.google.cloud.talent.v4beta1.RequestMetadata;
import com.google.cloud.talent.v4beta1.SearchJobsRequest;
import com.google.cloud.talent.v4beta1.SearchJobsResponse;
import com.google.cloud.talent.v4beta1.TenantName;
import com.google.protobuf.Duration;
import com.google.type.LatLng;
import java.io.IOException;

public class CommuteSearchJobs {

  public static void searchJobs() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String tenantId = "your-tenant-id";
    searchJobs(projectId, tenantId);
  }

  // Search Jobs with histogram queries.
  public static void searchJobs(String projectId, String tenantId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
      TenantName parent = TenantName.of(projectId, tenantId);
      String domain = "www.example.com";
      String sessionId = "Hashed session identifier";
      String userId = "Hashed user identifier";
      RequestMetadata requestMetadata =
          RequestMetadata.newBuilder()
              .setDomain(domain)
              .setSessionId(sessionId)
              .setUserId(userId)
              .build();

      CommuteMethod commuteMethod = CommuteMethod.DRIVING;
      long seconds = 3600L;
      Duration travelDuration = Duration.newBuilder().setSeconds(seconds).build();

      double latitude = 37.422408;
      double longitude = -122.084068;
      LatLng startCoordinates =
          LatLng.newBuilder().setLatitude(latitude).setLongitude(longitude).build();

      CommuteFilter commuteFilter =
          CommuteFilter.newBuilder()
              .setCommuteMethod(commuteMethod)
              .setTravelDuration(travelDuration)
              .setStartCoordinates(startCoordinates)
              .build();

      JobQuery jobQuery = JobQuery.newBuilder().setCommuteFilter(commuteFilter).build();
      SearchJobsRequest request =
          SearchJobsRequest.newBuilder()
              .setParent(parent.toString())
              .setRequestMetadata(requestMetadata)
              .setJobQuery(jobQuery)
              .build();

      for (SearchJobsResponse.MatchingJob responseItem :
          jobServiceClient.searchJobs(request).iterateAll()) {
        System.out.format("Job summary: %s%n", responseItem.getJobSummary());
        System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
        Job job = responseItem.getJob();
        System.out.format("Job name: %s%n", job.getName());
        System.out.format("Job title: %s%n", job.getTitle());
      }
    }
  }
}

Node.js

CTS 用のクライアント ライブラリをインストールして使用する方法については、CTS クライアント ライブラリをご覧ください。 詳細については、CTS Node.js API のリファレンス ドキュメントをご覧ください。

CTS への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


const talent = require('@google-cloud/talent').v4;

/** Search Jobs using commute distance */
function sampleSearchJobs(projectId, tenantId) {
  const client = new talent.JobServiceClient();
  // Iterate over all elements.
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  const formattedParent = client.tenantPath(projectId, tenantId);
  const domain = 'www.example.com';
  const sessionId = 'Hashed session identifier';
  const userId = 'Hashed user identifier';
  const requestMetadata = {
    domain: domain,
    sessionId: sessionId,
    userId: userId,
  };
  const commuteMethod = 'TRANSIT';
  const seconds = 1800;
  const travelDuration = {
    seconds: seconds,
  };
  const latitude = 37.422408;
  const longitude = 122.084068;
  const startCoordinates = {
    latitude: latitude,
    longitude: longitude,
  };
  const commuteFilter = {
    commuteMethod: commuteMethod,
    travelDuration: travelDuration,
    startCoordinates: startCoordinates,
  };
  const jobQuery = {
    commuteFilter: commuteFilter,
  };
  const request = {
    parent: formattedParent,
    requestMetadata: requestMetadata,
    jobQuery: jobQuery,
  };

  client
    .searchJobs(request)
    .then(responses => {
      const resources = responses[0];
      for (const resource of resources) {
        console.log(`Job summary: ${resource.jobSummary}`);
        console.log(`Job title snippet: ${resource.jobTitleSnippet}`);
        const job = resource.job;
        console.log(`Job name: ${job.name}`);
        console.log(`Job title: ${job.title}`);
      }
    })
    .catch(err => {
      console.error(err);
    });
}

Python

CTS 用のクライアント ライブラリをインストールして使用する方法については、CTS クライアント ライブラリをご覧ください。 詳細については、CTS Python API のリファレンス ドキュメントをご覧ください。

CTS への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


from google.cloud import talent

def search_jobs(project_id, tenant_id):
    """Search Jobs using commute distance"""

    client = talent.JobServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'

    if isinstance(project_id, bytes):
        project_id = project_id.decode("utf-8")
    if isinstance(tenant_id, bytes):
        tenant_id = tenant_id.decode("utf-8")
    parent = f"projects/{project_id}/tenants/{tenant_id}"
    domain = "www.example.com"
    session_id = "Hashed session identifier"
    user_id = "Hashed user identifier"
    request_metadata = talent.RequestMetadata(
        domain=domain, session_id=session_id, user_id=user_id
    )
    commute_method = talent.CommuteMethod.TRANSIT
    seconds = 1800
    travel_duration = {"seconds": seconds}
    latitude = 37.422408
    longitude = -122.084068
    start_coordinates = {"latitude": latitude, "longitude": longitude}
    commute_filter = talent.CommuteFilter(
        commute_method=commute_method,
        travel_duration=travel_duration,
        start_coordinates=start_coordinates,
    )
    job_query = talent.JobQuery(commute_filter=commute_filter)

    # Iterate over all results
    results = []
    request = talent.SearchJobsRequest(
        parent=parent,
        request_metadata=request_metadata,
        job_query=job_query,
    )
    for response_item in client.search_jobs(request=request).matching_jobs:
        print(f"Job summary: {response_item.job_summary}")
        print(f"Job title snippet: {response_item.job_title_snippet}")
        job = response_item.job
        results.append(job.name)
        print(f"Job name: {job.name}")
        print(f"Job title: {job.title}")
    return results

必須項目

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

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

  • startCoordinates: 通勤時間の計算で出発地として使用する場所の緯度と経度。このフィールドには LatLng オブジェクトを指定できます。

  • roadTraffic または departureTime: 通勤に関する検索の結果は、実際の交通状況ではなく、過去の集計データに基づいています。ユーザーは、クエリを送信した時刻に関係なく、同じ通勤に関する検索結果を受け取ります。

    • roadTraffic: 通勤時間の計算に使用する混雑度を指定します。BUSY_HOUR/TRAFFIC_FREE オプションでは、それぞれ朝のラッシュアワーと深夜の平均的な交通状況が計算されます。departureTime が指定されている場合、このフィールドは使用できません。

    • departureTime: 渋滞状況の計算で使用する出発時間。startLocation のタイムゾーンでの時間を表す 0~23 の整数を使用できます。交通状況は、指定された時刻の平均交通状況から計算されます。roadTraffic が指定されている場合、このフィールドは使用できません。

省略可能項目

  • allowImpreciseAddresses: 「正確」な住所は、番地レベルの住所または GPS 座標として定義されます。allowImpreciseAddressestrue に設定されている場合、「不正確」な住所(市区町村、都道府県、または国のみ)が指定された求人も返されることがあります。市区町村以上のレベルの住所では、API はテキスト マッチングを使用して結果を返します。この項目を false に設定するか、指定していない場合は、正確な住所を含む求人だけが返されます。