חיפוש נסיעה לעבודה (גרסה 3)

בקשות לחיפוש משרות יכולות לכלול מסנן של זמן נסיעה לעבודה, שמגביל את המשרות שמוחזרות לאלה שנמצאות בטווח של זמן נסיעה מוגדר מנקודת התחלה. התוצאות כוללות את זמן הנסיעה המשוער בשניות למשרות שתואמות לחיפוש.

כדי להחזיר משרות עם זמן נסיעה ספציפי, שולחים בקשת jobs.search וכוללים אובייקט CommuteFilter בשדה JobQuery.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
}

Ruby

מידע נוסף על התקנה ויצירה של לקוח Cloud Talent Solution זמין במאמר בנושא ספריות לקוח של Cloud Talent Solution.

# project_id              = "Id of the project"
# commute_method          = "The method of transportation for which to calculate the commute time"
# travel_duration         = "The maximum travel time in seconds"
# start_coordinates       = "The latitude and longitude of the location from which to calculate the commute time"

require "google/apis/jobs_v3"

jobs = Google::Apis::JobsV3
talent_solution_client = jobs::CloudTalentSolutionService.new
# @see https://developers.google.com/identity/protocols/application-default-credentials#callingruby
talent_solution_client.authorization = Google::Auth.get_application_default(
  "https://www.googleapis.com/auth/jobs"
)

# Make sure to set the request_metadata the same as the associated search request
request_metadata = jobs::RequestMetadata.new user_id:    "HashedUserId",
                                             session_id: "HashedSessionId",
                                             domain:     "www.google.com"
# Set location filter
commute_filter = jobs::CommuteFilter.new road_traffic:      "TRAFFIC_FREE",
                                         commute_method:    commute_method,
                                         travel_duration:   travel_duration,
                                         start_coordinates: start_coordinates
# Perform a search for analyst  related jobs
search_jobs_request =
  jobs::SearchJobsRequest.new request_metadata:            request_metadata,
                              job_query:                   (jobs::JobQuery.new commute_filter: commute_filter),
                              job_view:                    "JOB_VIEW_FULL",
                              require_precise_result_size: true
search_jobs_response = talent_solution_client.search_jobs project_id, search_jobs_request
puts search_jobs_response.to_json
search_jobs_response

שדות חובה

  • ‫commuteMethod: אמצעי התחבורה שעבורו יחושב זמן הנסיעה. האפשרויות הן DRIVING ו-TRANSIT. כל הגרסאות מאז V3p1beta1 יכללו גם את מצבי התחבורה WALKING ו-CYCLING. יכול להיות שמסלולי הליכה ורכיבה על אופניים לא ישקפו את התנאים בעולם האמיתי, כמו עבודות בנייה, או שלא יכללו שבילי הליכה או שבילי אופניים ברורים. התשובות האלה יכללו את warnings בתוצאה שמוחזרת, ואתם צריכים להציג אותה למשתמשים.

  • ‫travelDuration: זמן הנסיעה המקסימלי בשניות. הערך המקסימלי המותר הוא 3600s (שעה אחת). הפורמט הוא 123s.

  • ‫startCoordinates: קו הרוחב וקו האורך של המיקום שממנו רוצים לחשב את זמן הנסיעה. מקבלת אובייקט LatLng.

שדות אופציונליים

  • ‫allowImpreciseAddresses: כתובות 'מדויקות' מוגדרות ככתובות ברמת הרחוב או כקואורדינטות GPS. אם הערך של allowImpreciseAddresses הוא true, יכול להיות שיוחזרו גם משרות עם כתובות 'לא מדויקות' (רק עיר, מדינה או ארץ). לכתובות ברמת העיר וברמה גסה יותר, נעשה שימוש בהתאמה לטקסט. אם השדה הזה מוגדר לערך false או לא מצוין, בחיפוש הנסיעה לעבודה יוצגו רק משרות שכוללות כתובות מדויקות.
  • ‫roadTraffic: מציין את צפיפות התנועה שבה יש להשתמש כשמחשבים את זמן הנסיעה לעבודה. האפשרויות הן TRAFFIC_FREE או BUSY_HOUR. אסור להשתמש במאפיין הזה אם מציינים את המאפיין departureHourLocal.

  • ‫departureTime: שעת ההמראה שמשמשת לחישוב ההשפעה על התנועה. הפונקציה מקבלת מספר שלם בין 0 ל-23, שמייצג את השעה באזור הזמן של startLocation. אסור להשתמש במאפיין הזה אם מציינים את המאפיין roadTraffic.