通勤时间搜索

搜索请求可包含通勤时间过滤条件,以便仅返回从起始点开始通勤时间在指定行程时间内的职位。结果包括匹配职位的预计通勤时间,以秒为单位。

要返回特定通勤时间内的职位,请发送 jobs.search 请求,并在 JobQuery.commuteFilter 字段中包含 CommuteFilter 对象。Cloud Talent Solution 使用职位的 address 来计算该职位的通勤时间。如果未提供详细地址,Cloud Talent Solution 会尝试推断职位的实际街道地址。

Java


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());
      }
    }
  }
}

Java

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


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());
      }
    }
  }
}

Python

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


from google.cloud import talent
from google.cloud.talent import enums
import six

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, six.binary_type):
        project_id = project_id.decode("utf-8")
    if isinstance(tenant_id, six.binary_type):
        tenant_id = tenant_id.decode("utf-8")
    parent = client.tenant_path(project_id, tenant_id)
    domain = "www.example.com"
    session_id = "Hashed session identifier"
    user_id = "Hashed user identifier"
    request_metadata = {"domain": domain, "session_id": session_id, "user_id": user_id}
    commute_method = enums.CommuteMethod.TRANSIT
    seconds = 1800
    travel_duration = {"seconds": seconds}
    latitude = 37.422408
    longitude = -122.084068
    start_coordinates = {"latitude": latitude, "longitude": longitude}
    commute_filter = {
        "commute_method": commute_method,
        "travel_duration": travel_duration,
        "start_coordinates": start_coordinates,
    }
    job_query = {"commute_filter": commute_filter}

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

Ruby

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

require "google/cloud/talent"

# Instantiate a client
job_service = Google::Cloud::Talent.job_service

# project_id = "Your Google Cloud Project ID"
# tenant_id = "Your Tenant ID (using tenancy is optional)"
formatted_parent = job_service.tenant_path project: project_id, tenant: tenant_id
domain = "www.example.com"
session_id = "Hashed session identifier"
user_id = "Hashed user identifier"
request_metadata = {
  domain:     domain,
  session_id: session_id,
  user_id:    user_id
}
commute_method = :TRANSIT
seconds = 1800
travel_duration = { seconds: seconds }
latitude = 37.422408
longitude = -122.084068
start_coordinates = { latitude: latitude, longitude: longitude }
commute_filter = {
  commute_method:    commute_method,
  travel_duration:   travel_duration,
  start_coordinates: start_coordinates
}
job_query = { commute_filter: commute_filter }

# Iterate over all results.
response = job_service.search_jobs parent:           formatted_parent,
                                   request_metadata: request_metadata,
                                   job_query:        job_query
response.matching_jobs.each do |matching_job|
  puts "Job summary: #{matching_job.job_summary}"
  puts "Job title snippet: #{matching_job.job_title_snippet}"
  job = matching_job.job
  puts "Job name: #{job.name}"
  puts "Job title: #{job.title}"
end

C#

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

public static object CommuteSearchJobs(string projectId, string tenantId)
{
    JobServiceClient jobServiceClient = JobServiceClient.Create();
    TenantName name = TenantName.FromProjectTenant(projectId, tenantId);

    string domain = "www.example.com";
    string sessionId = "Hashed session identifier";
    string userId = "Hashed user identifier";
    RequestMetadata requestMetadata = new RequestMetadata
    {
        Domain = domain,
        SessionId = sessionId,
        UserId = userId
    };

    CommuteMethod commuteMethod = CommuteMethod.Driving;
    long seconds = 3600L;
    Duration travelDuration = new Duration
    {
        Seconds = seconds
    };

    double latitude = 37.422408;
    double longitude = -122.084068;
    LatLng startCoordinates = new LatLng
    {
        Latitude = latitude,
        Longitude = longitude
    };

    CommuteFilter commuteFilter = new CommuteFilter
    {
        CommuteMethod = commuteMethod,
        TravelDuration = travelDuration,
        StartCoordinates = startCoordinates
    };

    JobQuery jobQuery = new JobQuery
    {
        CommuteFilter = commuteFilter
    };

    SearchJobsRequest request = new SearchJobsRequest
    {
        ParentAsTenantName = name,
        RequestMetadata = requestMetadata,
        JobQuery = jobQuery
    };

    var response = jobServiceClient.SearchJobs(request);
    foreach (var result in response)
    {
        Console.WriteLine($"Job summary: {result.JobSummary}");
        Console.WriteLine($"Job title snippet: {result.JobTitleSnippet}");
        Job job = result.Job;
        Console.WriteLine($"Job name: {job.Name}");
        Console.WriteLine($"Job title: {job.Title}");
    }

    return 0;
}

必填字段

  • commuteMethod:用于计算通勤时间的交通方法。选项包括 DRIVINGTRANSITWALKINGCYCLING 出行方式。步行和骑行路线可能无法反映现实情况(如施工路段),或不包括专门的步行或自行车道。返回的结果中将包含针对这些响应的 warnings,您必须向用户显示这些信息。

  • travelDuration:最长行程时间,以秒为单位。允许的最大值为 3600s(一小时)。格式为 123s

  • startCoordinates:用于计算通勤时间的起始地点的纬度和经度。该字段接受 LatLng 对象。

  • roadTrafficdepartureTime:通勤时间搜索结果基于历史记录数据和汇总数据,而不是实时路况信息。无论用户在一天中的什么时间发送查询,他们都会收到相同的通勤时间搜索结果。

    • roadTraffic:指定计算通勤时间时要使用的车流密度。BUSY_HOUR/TRAFFIC_FREE 选项分别是早高峰时段和午夜的平均路况信息。如果指定了 departureTime,则此字段不得存在。

    • departureTime:用于计算交通影响的出发小时数。接受 0 到 23 之间的整数,表示 startLocation 的时区中的小时。路况信息是根据一天中指定时间的平均路况信息计算得出的。如果指定了 roadTraffic,则此字段不得存在。

可选字段

  • allowImpreciseAddresses:“精确”地址定义为街道级地址或 GPS 坐标。如果 allowImpreciseAddresses 设置为 true,也可以返回地址“不精确”(仅包含城市、州/省或国家/地区信息)的职位。对于城市级别和更宽泛级别的地址,API 使用文本匹配来返回结果。如果此字段设置为 false 或未指定,则通勤时间搜索仅返回包含精确地址的职位。