通勤时间搜索 (v3)

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

要返回特定通勤时间内的职位,请发送 jobs.search 请求,并在 JobQuery.commuteFilter 字段中包含 CommuteFilter 对象。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(一小时)。格式为 123s

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

可选字段

  • allowImpreciseAddresses:“精确”地址定义为街道级地址或 GPS 坐标。如果 allowImpreciseAddresses 设置为 true,也可以返回地址“不精确”(仅包含城市、州/省或国家/地区信息)的职位。对于城市级别和更宽泛级别的地址,系统会使用文本匹配。 如果此字段设置为 false 或未指定,则通勤时间搜索仅返回包含精确地址的职位。
  • roadTraffic:指定计算通勤时间时要使用的车流密度。选项为 TRAFFIC_FREEBUSY_HOUR。如果指定了 departureHourLocal,则请勿提供此项。

  • departureTime:用于计算交通影响的出发小时数。接受 0 到 23 之间的整数,表示 startLocation 的时区中的小时。如果指定了 roadTraffic,则请勿提供此项。