通勤时间搜索

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

要返回特定通勤时间内的职位,请发送 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 {
    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.printf("Job summary: %s\n", responseItem.getJobSummary());
        System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
        Job job = responseItem.getJob();
        System.out.printf("Job name: %s\n", job.getName());
        System.out.printf("Job title: %s\n", job.getTitle());
      }
    }
  }
}

Java

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


/** Search Jobs using commute distance */
public static void searchJobs(String projectId, String tenantId) {
  try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
    // projectId = "Your Google Cloud Project ID";
    // tenantId = "Your Tenant ID (using tenancy is optional)";
    TenantOrProjectName 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.TRANSIT;
    long seconds = 1800L;
    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.printf("Job summary: %s\n", responseItem.getJobSummary());
      System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
      Job job = responseItem.getJob();
      System.out.printf("Job name: %s\n", job.getName());
      System.out.printf("Job title: %s\n", job.getTitle());
    }
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);
  }
}

PHP

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

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\JobServiceClient;
use Google\Cloud\Talent\V4beta1\CommuteFilter;
use Google\Cloud\Talent\V4beta1\CommuteMethod;
use Google\Cloud\Talent\V4beta1\JobQuery;
use Google\Cloud\Talent\V4beta1\RequestMetadata;
use Google\Protobuf\Duration;
use Google\Type\LatLng;

/** Search Jobs using commute distance */
function sampleSearchJobs($projectId, $tenantId)
{

    $jobServiceClient = new JobServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID (using tenancy is optional)';
    $formattedParent = $jobServiceClient->tenantName($projectId, $tenantId);
    $domain = 'www.example.com';
    $sessionId = 'Hashed session identifier';
    $userId = 'Hashed user identifier';
    $requestMetadata = new RequestMetadata();
    $requestMetadata->setDomain($domain);
    $requestMetadata->setSessionId($sessionId);
    $requestMetadata->setUserId($userId);
    $commuteMethod = CommuteMethod::TRANSIT;
    $seconds = 1800;
    $travelDuration = new Duration();
    $travelDuration->setSeconds($seconds);
    $latitude = 37.422408;
    $longitude = 122.084068;
    $startCoordinates = new LatLng();
    $startCoordinates->setLatitude($latitude);
    $startCoordinates->setLongitude($longitude);
    $commuteFilter = new CommuteFilter();
    $commuteFilter->setCommuteMethod($commuteMethod);
    $commuteFilter->setTravelDuration($travelDuration);
    $commuteFilter->setStartCoordinates($startCoordinates);
    $jobQuery = new JobQuery();
    $jobQuery->setCommuteFilter($commuteFilter);

    try {
        // Iterate through all elements
        $pagedResponse = $jobServiceClient->searchJobs($formattedParent, $requestMetadata, ['customRankingInfo' => $customRankingInfo, 'orderBy' => $orderBy]);
        foreach ($pagedResponse->iterateAllElements() as $responseItem) {
            printf('Job summary: %s'.PHP_EOL, $responseItem->getJobSummary());
            printf('Job title snippet: %s'.PHP_EOL, $responseItem->getJobTitleSnippet());
            $job = $responseItem->getJob();
            printf('Job name: %s'.PHP_EOL, $job->getName());
            printf('Job title: %s'.PHP_EOL, $job->getTitle());
        }
    } finally {
        $jobServiceClient->close();
    }

}

Ruby

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


# Search Jobs using commute distance
def sample_search_jobs project_id, tenant_id
  # Instantiate a client
  job_client = Google::Cloud::Talent::JobService.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  # tenant_id = "Your Tenant ID (using tenancy is optional)"
  formatted_parent = job_client.class.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 = :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.
  job_client.search_jobs(formatted_parent, request_metadata, job_query: job_query).each do |element|
    puts "Job summary: #{element.job_summary}"
    puts "Job title snippet: #{element.job_title_snippet}"
    job = element.job
    puts "Job name: #{job.name}"
    puts "Job title: #{job.title}"
  end
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 或未指定,则通勤时间搜索仅返回包含精确地址的职位。