הטמעה של חיפוש נסיעות לעבודה בממשק המשתמש

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

  1. כדי להטמיע את החיפוש לפי נסיעה, צריך לקשר את Cloud Talent Solution לממשק המשתמש. כדי להגדיר את Cloud Talent Solution, תוכלו להיעזר במדריכים למתחילים.

  2. החישוב של זמן הנסיעה לעבודה מתבסס על נתוני הכתובות שהעליתם עם המשרות במהלך ההטמעה של CTS. כדי להפעיל את התכונה הזו בממשק המשתמש הקיים של CTS, שולחים בקשת jobs.search וכוללים אובייקט CommuteFilter בשדה JobQuery.commuteFilter. commuteMethod,‏ travelDuration,‏ startCoordinates וגם roadTraffic או departureTime הם שדות חובה.

Go

מידע על התקנת ספריית הלקוח של CTS ושימוש בה מופיע במאמר ספריות הלקוח של CTS. מידע נוסף מופיע במאמרי העזרה של CTS Go API.

כדי לבצע אימות ב-CTS, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	"cloud.google.com/go/talent/apiv4beta1/talentpb"
	"github.com/golang/protobuf/ptypes/duration"
	"google.golang.org/genproto/googleapis/type/latlng"
)

// commuteSearch searches for jobs within commute filter.
func commuteSearch(w io.Writer, projectID, companyID string) error {
	ctx := context.Background()

	// Initialize a jobService client.
	c, err := talent.NewJobClient(ctx)
	if err != nil {
		return fmt.Errorf("talent.NewJobClient: %w", err)
	}
	defer c.Close()

	// Construct a jobQuery request with a commute filter.
	jobQuery := &talentpb.JobQuery{
		CommuteFilter: &talentpb.CommuteFilter{
			CommuteMethod:  talentpb.CommuteMethod_TRANSIT,
			TravelDuration: &duration.Duration{Seconds: 1800},
			StartCoordinates: &latlng.LatLng{
				Latitude:  37.422408,
				Longitude: -122.085609,
			},
		},
	}
	if companyID != "" {
		jobQuery.Companies = []string{fmt.Sprintf("projects/%s/companies/%s", projectID, companyID)}
	}

	// Construct a searchJobs request with a jobQuery.
	req := &talentpb.SearchJobsRequest{
		Parent: fmt.Sprintf("projects/%s", projectID),
		// Make sure to set the RequestMetadata the same as the associated
		// search request.
		RequestMetadata: &talentpb.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,
	}

	resp, err := c.SearchJobs(ctx, req)
	if err != nil {
		return fmt.Errorf("SearchJobs: %w", err)
	}

	for _, job := range resp.GetMatchingJobs() {
		fmt.Fprintf(w, "Matcing Job: %q\n", job.GetJob().GetName())
		fmt.Fprintf(w, "Job address: %v\n", job.GetCommuteInfo().GetJobLocation().GetPostalAddress().GetAddressLines())
	}

	return nil
}

Java

מידע על התקנת ספריית הלקוח של CTS ושימוש בה מופיע במאמר ספריות הלקוח של CTS. מידע נוסף מופיע במאמרי העזרה של CTS Java API.

כדי לבצע אימות ב-CTS, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


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

Node.js

מידע על התקנת ספריית הלקוח של CTS ושימוש בה מופיע במאמר ספריות הלקוח של CTS. מידע נוסף מופיע במאמרי העזרה של CTS Node.js API.

כדי לבצע אימות ב-CTS, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


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, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


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

המלצות לגבי ממשק המשתמש

  1. ב-Cloud Talent Solution אי אפשר לחפש לפי מרחק (באמצעות מסנן המיקום של CTS) וגם לפי זמן נסיעה באותה קריאה ל-API. כדי לאפשר למועמדים לגשת לשתי האפשרויות, אפשר להשתמש בגישה של 2 כרטיסיות או בגישה דומה.

  2. משנים את החלק הקדמי של האפליקציה כדי לוודא שהחלק האחורי מאכלס באופן אוטומטי את המידע הרלוונטי של מחפשי העבודה במסנן הנסיעה. הקצה העורפי צריך לקרוא ל-API כמו שהוא קורא לבקשת חיפוש רגילה.

  3. הוספת פריטים לממשק המשתמש:

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

    • תפריט נפתח עם אפשרויות לשיטת הנסיעה.

    • אפשרות להתאמת מצב התנועה.

    • זמן הנסיעה הכולל (זמן הנסיעה המקסימלי שנתמך הוא 60 דקות).

    • שעת ההתחלה של הנסיעה היומית.

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

  5. תוצאות החיפוש של הנסיעה לעבודה מבוססות על נתונים היסטוריים ומצטברים, ולא על מצב התנועה בזמן אמת. תנאי התנועה departureTime מחושבים על סמך תנאי התנועה הממוצעים בשעה שצוינה ביום. האפשרויות BUSY_HOUR/TRAFFIC_FREE בקטע roadTraffic הן מצב התנועה הממוצע בשעת העומס של הבוקר ובחצות, בהתאמה. המשתמשים מקבלים את אותן תוצאות חיפוש של נסיעה לעבודה, לא משנה באיזו שעה ביום הם שולחים שאילתה.

אתם יכולים להשתמש במפות Google כדי ליצור מפה על סמך נתוני זמן הנסיעה לעבודה שמוחזרים מ-CTS, ולהטמיע אותה בתוצאות שמוחזרות למועמד למשרה. חבילת Maps API כוללת כמה אפשרויות להצגת מפה. חלק מהאפשרויות של Maps API יעילות יותר מאחרות. לדוגמה, הדמיה של מפת חום ב-JavaScript של מפות Google בשילוב עם אשכול סמנים היא דרך יעילה להדמיה של המשרות הרלוונטיות שמוצגות לחיפוש עבודה באזור שנקבע לפי העדפות הנסיעה שהוגדרו. לעומת זאת, מצב הכוונה לא מציג את כל המשרות שמוחזרות בבקשת חיפוש, ולכן לא מומלץ להשתמש בו.

מידע נוסף על הטמעה של חיפוש נסיעות לעבודה זמין במדריך לחיפוש נסיעות לעבודה.