基于位置的搜索 (v3)

Java

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


/**
 * Basic location Search
 */
public static void basicLocationSearch(String companyName, String location, double distance)
    throws IOException, InterruptedException {
  // Make sure to set the requestMetadata the same as the associated search request
  RequestMetadata requestMetadata =
      new RequestMetadata()
          // Make sure to hash the userID
          .setUserId("HashedUserId")
          // Make sure to hash the sessionID
          .setSessionId("HashedSessionID")
          // Domain of the website where the search is conducted
          .setDomain("www.google.com");
  LocationFilter locationFilter =
      new LocationFilter().setAddress(location)
          .setDistanceInMiles(distance);
  JobQuery jobQuery = new JobQuery()
      .setLocationFilters(Arrays.asList(locationFilter));
  if (companyName != null) {
    jobQuery.setCompanyNames(Arrays.asList(companyName));
  }
  SearchJobsRequest request =
      new SearchJobsRequest()
          .setRequestMetadata(requestMetadata)
          .setJobQuery(jobQuery)
          .setSearchMode("JOB_SEARCH");
  SearchJobsResponse response =
      talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
  Thread.sleep(1000);
  System.out.println(response);
}

Python

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

def basic_location_search(client_service, company_name, location, distance):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    location_filter = {'address': location, 'distance_in_miles': distance}
    job_query = {'location_filters': [location_filter]}
    if company_name is not None:
        job_query.update({'company_names': [company_name]})
    request = {
        'job_query': job_query,
        'request_metadata': request_metadata,
        'search_mode': 'JOB_SEARCH',
    }
    response = client_service.projects().jobs().search(
        parent=parent, body=request).execute()
    print(response)

C#

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


public static void BasicLocationSearch(string companyName, string location, double distance)
{
    RequestMetadata requestMetadata = new RequestMetadata()
    {
        // Make sure to hash your userID
        UserId = "HashedUserId",
        // Make sure to hash the sessionID
        SessionId = "HashedSessionId",
        // Domain of the website where the search is conducted
        Domain = "www.google.com"
    };

    LocationFilter locationFilter = new LocationFilter()
    {
        Address = location,
        DistanceInMiles = distance
    };

    JobQuery jobQuery = new JobQuery()
    {
        LocationFilters = new List<LocationFilter>()
        {
            locationFilter
        }
    };

    if (companyName != null)
    {
        jobQuery.CompanyNames = new List<string>
        {
            companyName
        };
    }

    SearchJobsRequest searchJobRequest = new SearchJobsRequest()
    {
        RequestMetadata = requestMetadata,
        JobQuery = jobQuery,
        SearchMode = "JOB_SEARCH"
    };

    SearchJobsResponse searchJobsResponse = jobServiceClient.Projects.Jobs.Search(searchJobRequest, parent).Execute();

    Console.WriteLine("Jobs basic location searched: " + ToJsonString(searchJobsResponse));
}

Go

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


// basicLocationSearch searches for jobs within distance of location.
func basicLocationSearch(w io.Writer, projectID, companyName, location string, distance float64) (*talent.SearchJobsResponse, error) {
	ctx := context.Background()

	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		return nil, fmt.Errorf("google.DefaultClient: %v", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %v", err)
	}

	jobQuery := &talent.JobQuery{
		LocationFilters: []*talent.LocationFilter{
			{
				Address:         location,
				DistanceInMiles: distance,
			},
		},
	}

	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",
	}
	resp, err := service.Projects.Jobs.Search(parent, req).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to search for jobs with basic location %s within %f miles: %v", location, distance, err)
	}

	fmt.Fprintln(w, "Jobs:")
	for _, j := range resp.MatchingJobs {
		fmt.Fprintf(w, "\t%q\n", j.Job.Name)
	}

	return resp, nil
}

Node.js

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


/**
 * Basic location Search
 */
const basicLocationSearch = async (
  jobServiceClient,
  companyName,
  location,
  distance
) => {
  try {
    const locationFilter = {
      address: location,
      distanceInMiles: distance,
    };

    const jobQuery = {
      locationFilters: [locationFilter],
    };

    if (companyName) {
      jobQuery.companyNames = [companyName];
    }

    const request = {
      parent: `projects/${PROJECT_ID}`,
      resource: {
        jobQuery: jobQuery,
        requestMetadata: REQUEST_META_DATA,
        searchMode: 'JOB_SEARCH',
      },
    };

    const result = await jobServiceClient.projects.jobs.search(request);

    console.log(JSON.stringify(result.data));
  } catch (e) {
    console.error(e);
    throw e;
  }
};

Ruby

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

# project_id       = "Id of the project."
# company_name     = "The resource name of the company listing the job. The format is "projects/{project_id}/companies/{company_id}""
# location         = "Location of the center where the search is based on."
# distance         = "The distance from the provided location in miles in which to search."
require "google/apis/jobs_v3"
# Instantiate the client
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 requestMetadata 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
location_filter = jobs::LocationFilter.new address:           location,
                                           distance_in_miles: distance
# Perform a search for analyst  related jobs
job_query = jobs::JobQuery.new location_filters: [location_filter],
                               company_names:    [company_name]

search_jobs_request = jobs::SearchJobsRequest.new request_metadata: request_metadata,
                                                  job_query:        job_query,
                                                  search_mode:      "JOB_SEARCH"

search_jobs_response = talent_solution_client.search_jobs project_id, search_jobs_request

puts search_jobs_response.to_json
search_jobs_response

Java

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


/**
 * Keyword location Search
 */
public static void keywordLocationSearch(String companyName, String location, double distance,
    String keyword)
    throws IOException, InterruptedException {
  // Make sure to set the requestMetadata the same as the associated search request
  RequestMetadata requestMetadata =
      new RequestMetadata()
          // Make sure to hash the userID
          .setUserId("HashedUserId")
          // Make sure to hash the sessionID
          .setSessionId("HashedSessionID")
          // Domain of the website where the search is conducted
          .setDomain("www.google.com");
  LocationFilter locationFilter =
      new LocationFilter().setAddress(location)
          .setDistanceInMiles(distance);
  JobQuery jobQuery =
      new JobQuery()
          .setQuery(keyword)
          .setLocationFilters(Arrays.asList(locationFilter));
  if (companyName != null) {
    jobQuery.setCompanyNames(Arrays.asList(companyName));
  }
  SearchJobsRequest request =
      new SearchJobsRequest()
          .setRequestMetadata(requestMetadata)
          .setJobQuery(jobQuery)
          .setSearchMode("JOB_SEARCH");
  SearchJobsResponse response =
      talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
  Thread.sleep(1000);
  System.out.println(response);
}

Python

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

def keyword_location_search(client_service, company_name, location, distance,
                            keyword):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    location_filter = {'address': location, 'distance_in_miles': distance}
    job_query = {'location_filters': [location_filter], 'query': keyword}
    if company_name is not None:
        job_query.update({'company_names': [company_name]})
    request = {
        'job_query': job_query,
        'request_metadata': request_metadata,
        'search_mode': 'JOB_SEARCH',
    }
    response = client_service.projects().jobs().search(
        parent=parent, body=request).execute()
    print(response)

C#

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


public static void KeywordLocationSearch(string companyName, string location, double distance, string keyword)
{
    RequestMetadata requestMetadata = new RequestMetadata()
    {
        // Make sure to hash your userID
        UserId = "HashedUserId",
        // Make sure to hash the sessionID
        SessionId = "HashedSessionId",
        // Domain of the website where the search is conducted
        Domain = "www.google.com"
    };

    LocationFilter locationFilter = new LocationFilter()
    {
        Address = location,
        DistanceInMiles = distance
    };

    JobQuery jobQuery = new JobQuery()
    {
        LocationFilters = new List<LocationFilter>()
        {
            locationFilter
        },
        Query = keyword
    };

    if (companyName != null)
    {
        jobQuery.CompanyNames = new List<string>
        {
            companyName
        };
    }

    SearchJobsRequest searchJobRequest = new SearchJobsRequest()
    {
        RequestMetadata = requestMetadata,
        JobQuery = jobQuery,
        SearchMode = "JOB_SEARCH"
    };

    SearchJobsResponse searchJobsResponse = jobServiceClient.Projects.Jobs.Search(searchJobRequest, parent).Execute();

    Console.WriteLine("Jobs location and keyword searched: " + ToJsonString(searchJobsResponse));
}

Go

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


// keywordLocationSearch searches for jobs with given keyword and within the
// distance of given location.
func keywordLocationSearch(w io.Writer, projectID, companyName, location string, distance float64, keyword string) (*talent.SearchJobsResponse, error) {
	ctx := context.Background()

	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		return nil, fmt.Errorf("google.DefaultClient: %v", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %v", err)
	}

	jobQuery := &talent.JobQuery{
		LocationFilters: []*talent.LocationFilter{
			{
				Address:         location,
				DistanceInMiles: distance,
			},
		},
		Query: keyword,
	}

	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",
	}
	resp, err := service.Projects.Jobs.Search(parent, req).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to search for jobs with keyword %q in location %v within %f miles: %v", keyword, location, distance, err)
	}

	fmt.Fprintln(w, "Jobs:")
	for _, j := range resp.MatchingJobs {
		fmt.Fprintf(w, "\t%q\n", j.Job.Name)
	}

	return resp, nil
}

Node.js

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


/**
 * Keyword location Search
 */
const keywordLocationSearch = async (
  jobServiceClient,
  companyName,
  location,
  distance,
  keyword
) => {
  try {
    const locationFilter = {
      address: location,
      distanceInMiles: distance,
    };

    const jobQuery = {
      locationFilters: [locationFilter],
      query: keyword,
    };

    if (companyName) {
      jobQuery.companyNames = [companyName];
    }

    const request = {
      parent: `projects/${PROJECT_ID}`,
      resource: {
        jobQuery: jobQuery,
        requestMetadata: REQUEST_META_DATA,
        searchMode: 'JOB_SEARCH',
      },
    };

    const result = await jobServiceClient.projects.jobs.search(request);

    console.log(JSON.stringify(result.data));
  } catch (e) {
    console.error(e);
    throw e;
  }
};

Ruby

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

# project_id      = "Id of the project."
# company_name    = "The resource name of the company listing the job. The format is "projects/{project_id}/companies/{company_id}""
# location        = "Location of the center where the search is based on."
# distance        = "The distance from the provided location in miles in which to search."
# keyword         = "Keyword of the search."
require "google/apis/jobs_v3"
# Instantiate the client
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 requestMetadata 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
location_filter = jobs::LocationFilter.new address:           location,
                                           distance_in_miles: distance
# Perform a search for analyst  related jobs
job_query = jobs::JobQuery.new location_filters: [location_filter],
                               query:            keyword,
                               company_names:    [company_name]

search_jobs_request = jobs::SearchJobsRequest.new request_metadata: request_metadata,
                                                  job_query:        job_query,
                                                  search_mode:      "JOB_SEARCH"

search_jobs_response = talent_solution_client.search_jobs project_id, search_jobs_request

puts search_jobs_response.to_json
search_jobs_response
所有字段均为选填:

  • address 是实际工作地点,以字符串表示。可以是街道地址,也可以是任何级别的地址(最高为国家/地区)。例如,可以是“123 Main Street,Anytown,WA,USA”,也可以是简单的“USA”。

  • distanceInMiles:搜索范围,以与 namelatLng 之间的距离计(以英里为单位)。默认值是 20。最大值为 5000。

    • 如果 name 的值是街道地址,则返回距离该地址 distanceInMiles 范围内的招聘信息。
    • 如果 name 的值是街区或城市,则返回距离该街区/城市中心 distanceInMiles 范围内的招聘信息。要返回某个街区/城市内的所有招聘信息,需将 distanceInMiles 设置为 0。如果 distanceInMiles 大于 0,则应用的搜索半径为街区/城市的地理边界加上请求中设置的 distanceInMiles(地理边界按 Google Maps Geocoding API 界定)。
    • 如果 name 的值是非正式区域名称,比如湾区 (Bay Area) 或硅谷 (Silicon Valley),则应用的搜索半径是该区域的界定地理边界加上请求中设置的 distanceInMiles。
    • 如果 name 的值是州或国家/地区,则服务会忽略 distanceInMiles,返回指定州或国家/地区内的招聘信息。

基本位置(仅含城市级别的位置)和输出

Java

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


/**
 * City location Search
 */
public static void cityLocationSearch(String companyName, String location)
    throws IOException, InterruptedException {
  // Make sure to set the requestMetadata the same as the associated search request
  RequestMetadata requestMetadata =
      new RequestMetadata()
          // Make sure to hash the userID
          .setUserId("HashedUserId")
          // Make sure to hash the sessionID
          .setSessionId("HashedSessionID")
          // Domain of the website where the search is conducted
          .setDomain("www.google.com");
  LocationFilter locationFilter = new LocationFilter()
      .setAddress(location);
  JobQuery jobQuery = new JobQuery()
      .setLocationFilters(Arrays.asList(locationFilter));
  if (companyName != null) {
    jobQuery.setCompanyNames(Arrays.asList(companyName));
  }
  SearchJobsRequest request =
      new SearchJobsRequest()
          .setRequestMetadata(requestMetadata)
          .setJobQuery(jobQuery)
          .setSearchMode("JOB_SEARCH");
  SearchJobsResponse response =
      talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
  Thread.sleep(1000);
  System.out.println(response);
}

Python

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

def city_location_search(client_service, company_name, location):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    location_filter = {'address': location}
    job_query = {'location_filters': [location_filter]}
    if company_name is not None:
        job_query.update({'company_names': [company_name]})
    request = {
        'job_query': job_query,
        'request_metadata': request_metadata,
        'search_mode': 'JOB_SEARCH',
    }
    response = client_service.projects().jobs().search(
        parent=parent, body=request).execute()
    print(response)

C#

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


public static void CityLocationSearch(string companyName, string location)
{
    RequestMetadata requestMetadata = new RequestMetadata()
    {
        // Make sure to hash your userID
        UserId = "HashedUserId",
        // Make sure to hash the sessionID
        SessionId = "HashedSessionId",
        // Domain of the website where the search is conducted
        Domain = "www.google.com"
    };

    LocationFilter locationFilter = new LocationFilter()
    {
        Address = location
    };

    JobQuery jobQuery = new JobQuery()
    {
        LocationFilters = new List<LocationFilter>()
        {
            locationFilter
        }
    };

    if (companyName != null)
    {
        jobQuery.CompanyNames = new List<string>
        {
            companyName
        };
    }

    SearchJobsRequest searchJobRequest = new SearchJobsRequest()
    {
        RequestMetadata = requestMetadata,
        JobQuery = jobQuery,
        SearchMode = "JOB_SEARCH"
    };

    SearchJobsResponse searchJobsResponse = jobServiceClient.Projects.Jobs.Search(searchJobRequest, parent).Execute();

    Console.WriteLine("Jobs city level searched: " + ToJsonString(searchJobsResponse));
}

Go

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


// cityLocationSearch searches for jobs in the same city of given location.
func cityLocationSearch(w io.Writer, projectID, companyName, location string) (*talent.SearchJobsResponse, error) {
	ctx := context.Background()

	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		return nil, fmt.Errorf("google.DefaultClient: %v", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %v", err)
	}

	jobQuery := &talent.JobQuery{
		LocationFilters: []*talent.LocationFilter{
			{
				Address: location,
			},
		},
	}

	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",
	}
	resp, err := service.Projects.Jobs.Search(parent, req).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to search for jobs with city location %s: %v", location, err)
	}

	fmt.Fprintln(w, "Jobs:")
	for _, j := range resp.MatchingJobs {
		fmt.Fprintf(w, "\t%q\n", j.Job.Name)
	}

	return resp, nil
}

Node.js

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


/**
 * City location Search
 */
const cityLocationSearch = async (jobServiceClient, companyName, location) => {
  try {
    const locationFilter = {
      address: location,
    };

    const jobQuery = {
      locationFilters: [locationFilter],
    };

    if (companyName) {
      jobQuery.companyNames = [companyName];
    }

    const request = {
      parent: `projects/${PROJECT_ID}`,
      resource: {
        jobQuery: jobQuery,
        requestMetadata: REQUEST_META_DATA,
        searchMode: 'JOB_SEARCH',
      },
    };

    const result = await jobServiceClient.projects.jobs.search(request);

    console.log(JSON.stringify(result.data));
  } catch (e) {
    console.error(e);
    throw e;
  }
};

Ruby

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

# project_id       = "Id of the project."
# company_name     = "The resource name of the company listing the job. The format is "projects/{project_id}/companies/{company_id}""
# city             = "Name of the city where we want to do the job search."
require "google/apis/jobs_v3"
# Instantiate the client
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 requestMetadata 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
location_filter = jobs::LocationFilter.new address: city
# Perform a search for analyst  related jobs
job_query = jobs::JobQuery.new location_filters: [location_filter],
                               company_names:    [company_name]

search_jobs_request = jobs::SearchJobsRequest.new request_metadata: request_metadata,
                                                  job_query:        job_query,
                                                  search_mode:      "JOB_SEARCH"

search_jobs_response = talent_solution_client.search_jobs project_id, search_jobs_request

puts search_jobs_response.to_json
search_jobs_response

多个位置

如果有多个位置和多个半径传递给搜索查询,系统会考虑采用最大半径并将其应用到所有位置。 每个招聘信息限定 5 个位置。

Java

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


/**
 * Multiple locations Search
 */
public static void multiLocationsSearch(String companyName, String location1, double distance1,
    String location2)
    throws IOException, InterruptedException {
  // Make sure to set the requestMetadata the same as the associated search request
  RequestMetadata requestMetadata =
      new RequestMetadata()
          // Make sure to hash the 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()
          .setLocationFilters(
              Arrays.asList(
                  new LocationFilter().setAddress(location1).setDistanceInMiles(distance1),
                  new LocationFilter().setAddress(location2)));
  if (companyName != null) {
    jobQuery.setCompanyNames(Arrays.asList(companyName));
  }
  SearchJobsRequest request =
      new SearchJobsRequest()
          .setRequestMetadata(requestMetadata)
          .setJobQuery(jobQuery)
          .setSearchMode("JOB_SEARCH");
  SearchJobsResponse response =
      talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
  Thread.sleep(1000);
  System.out.println(response);
}

Python

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

def multi_locations_search(client_service, company_name, location1, distance1,
                           location2):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    location_filter1 = {'address': location1, 'distance_in_miles': distance1}
    location_filter2 = {'address': location2}
    job_query = {'location_filters': [location_filter1, location_filter2]}
    if company_name is not None:
        job_query.update({'company_names': [company_name]})
    request = {
        'job_query': job_query,
        'request_metadata': request_metadata,
        'search_mode': 'JOB_SEARCH',
    }
    response = client_service.projects().jobs().search(
        parent=parent, body=request).execute()
    print(response)

C#

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


public static void MultiLocationSearch(string companyName, string location1, double distance1, string location2)
{
    RequestMetadata requestMetadata = new RequestMetadata()
    {
        // Make sure to hash your userID
        UserId = "HashedUserId",
        // Make sure to hash the sessionID
        SessionId = "HashedSessionId",
        // Domain of the website where the search is conducted
        Domain = "www.google.com"
    };

    LocationFilter locationFilter1 = new LocationFilter()
    {
        Address = location1,
        DistanceInMiles = distance1
    };

    LocationFilter locationFilter2 = new LocationFilter()
    {
        Address = location2
    };

    JobQuery jobQuery = new JobQuery()
    {
        LocationFilters = new List<LocationFilter>()
        {
            locationFilter1,
            locationFilter2
        }
    };

    if (companyName != null)
    {
        jobQuery.CompanyNames = new List<string>
        {
            companyName
        };
    }

    SearchJobsRequest searchJobRequest = new SearchJobsRequest()
    {
        RequestMetadata = requestMetadata,
        JobQuery = jobQuery,
        SearchMode = "JOB_SEARCH"
    };

    SearchJobsResponse searchJobsResponse = jobServiceClient.Projects.Jobs.Search(searchJobRequest, parent).Execute();

    Console.WriteLine("Jobs multi location searched: " + ToJsonString(searchJobsResponse));
}

Go

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


// multiLocationsSearch searches for jobs that fall in the distance of any given
// locations.
func multiLocationsSearch(w io.Writer, projectID, companyName, location, location2 string, distance float64) (*talent.SearchJobsResponse, error) {
	ctx := context.Background()

	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		return nil, fmt.Errorf("google.DefaultClient: %v", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %v", err)
	}

	jobQuery := &talent.JobQuery{
		LocationFilters: []*talent.LocationFilter{
			{
				Address:         location,
				DistanceInMiles: distance,
			},
			{
				Address:         location2,
				DistanceInMiles: distance,
			},
		},
	}

	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",
	}
	resp, err := service.Projects.Jobs.Search(parent, req).Do()
	if err != nil {
		return nil, fmt.Errorf("Failed to search for jobs with multi locations %s and %s within %f miles, Err: %v", location, location2, distance, err)
	}

	fmt.Fprintln(w, "Jobs:")
	for _, j := range resp.MatchingJobs {
		fmt.Fprintf(w, "\t%q\n", j.Job.Name)
	}

	return resp, nil
}

Node.js

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


/**
 * Multiple locations Search
 */
const multiLocationsSearch = async (
  jobServiceClient,
  companyName,
  location1,
  distance1,
  location2
) => {
  try {
    const locationFilter1 = {
      address: location1,
      distanceInMiles: distance1,
    };

    const locationFilter2 = {
      address: location2,
    };

    const jobQuery = {
      locationFilters: [locationFilter1, locationFilter2],
    };

    if (companyName) {
      jobQuery.companyNames = [companyName];
    }

    const request = {
      parent: `projects/${PROJECT_ID}`,
      resource: {
        jobQuery: jobQuery,
        requestMetadata: REQUEST_META_DATA,
        searchMode: 'JOB_SEARCH',
      },
    };

    const result = await jobServiceClient.projects.jobs.search(request);

    console.log(JSON.stringify(result.data));
  } catch (e) {
    console.error(e);
    throw e;
  }
};

Ruby

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

# project_id       = "Id of the project."
# company_name     = "The resource name of the company listing the job. The format is "projects/{project_id}/companies/{company_id}""
# location1        = "Location of the center where the first search is based on"
# distance1        = "The distance from the provided location in miles in which to search."
# city             = "Name of the city where we want to do the second search."
require "google/apis/jobs_v3"
# Instantiate the client
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 requestMetadata 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
location_filter1 = jobs::LocationFilter.new address:           location1,
                                            distance_in_miles: distance1
location_filter2 = jobs::LocationFilter.new address: city2
# Perform a search for analyst  related jobs
job_query = jobs::JobQuery.new location_filters: [location_filter1, location_filter2],
                               company_names:    [company_name]

search_jobs_request = jobs::SearchJobsRequest.new request_metadata: request_metadata,
                                                  job_query:        job_query,
                                                  search_mode:      "JOB_SEARCH"

search_jobs_response = talent_solution_client.search_jobs project_id, search_jobs_request

puts search_jobs_response.to_json
search_jobs_response

设置 enableBroadening 标志

您可以通过 enableBroadening 标志放宽对位置和职位类别的限制,以增加返回的结果数。

Java

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


/**
 * Broadening location Search
 */
public static void broadeningLocationsSearch(String companyName, String location)
    throws IOException, InterruptedException {
  // Make sure to set the requestMetadata the same as the associated search request
  RequestMetadata requestMetadata =
      new RequestMetadata()
          // Make sure to hash the 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()
          .setLocationFilters(Arrays
              .asList(new LocationFilter().setAddress(location)));
  if (companyName != null) {
    jobQuery.setCompanyNames(Arrays.asList(companyName));
  }
  SearchJobsRequest request =
      new SearchJobsRequest()
          .setRequestMetadata(requestMetadata)
          .setJobQuery(jobQuery)
          .setEnableBroadening(true)
          .setSearchMode("JOB_SEARCH");
  SearchJobsResponse response =
      talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
  Thread.sleep(1000);
  System.out.println(response);
}

Python

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

def broadening_location_search(client_service, company_name, location):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    location_filter = {'address': location}
    job_query = {'location_filters': [location_filter]}
    if company_name is not None:
        job_query.update({'company_names': [company_name]})
    request = {
        'job_query': job_query,
        'request_metadata': request_metadata,
        'search_mode': 'JOB_SEARCH',
        'enable_broadening': True
    }
    response = client_service.projects().jobs().search(
        parent=parent, body=request).execute()
    print(response)

C#

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


public static void BroadeningLocationsSearch(string companyName, string location)
{
    RequestMetadata requestMetadata = new RequestMetadata()
    {
        // Make sure to hash your userID
        UserId = "HashedUserId",
        // Make sure to hash the sessionID
        SessionId = "HashedSessionId",
        // Domain of the website where the search is conducted
        Domain = "www.google.com"
    };

    LocationFilter locationFilter = new LocationFilter()
    {
        Address = location
    };

    JobQuery jobQuery = new JobQuery()
    {
        LocationFilters = new List<LocationFilter>()
        {
            locationFilter
        }
    };

    if (companyName != null)
    {
        jobQuery.CompanyNames = new List<string>
        {
            companyName
        };
    }

    SearchJobsRequest searchJobRequest = new SearchJobsRequest()
    {
        RequestMetadata = requestMetadata,
        JobQuery = jobQuery,
        EnableBroadening = true,
        SearchMode = "JOB_SEARCH"
    };

    SearchJobsResponse searchJobsResponse = jobServiceClient.Projects.Jobs.Search(searchJobRequest, parent).Execute();

    Console.WriteLine("Jobs broadening searched: " + ToJsonString(searchJobsResponse));
}

Go

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


// broadeningLocationSearch searches for jobs with a broadening area of given
// location.
func broadeningLocationSearch(w io.Writer, projectID, companyName, location string) (*talent.SearchJobsResponse, error) {
	ctx := context.Background()

	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		return nil, fmt.Errorf("google.DefaultClient: %v", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %v", err)
	}

	jobQuery := &talent.JobQuery{
		LocationFilters: []*talent.LocationFilter{
			{
				Address: location,
			},
		},
	}

	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",
		EnableBroadening: true,
	}
	resp, err := service.Projects.Jobs.Search(parent, req).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to search for jobs with broadening location %v: %v", location, err)
	}

	fmt.Fprintln(w, "Jobs:")
	for _, j := range resp.MatchingJobs {
		fmt.Fprintf(w, "\t%q\n", j.Job.Name)
	}

	return resp, nil
}

Node.js

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


/**
 * Broadening location Search
 */
const broadeningLocationsSearch = async (
  jobServiceClient,
  companyName,
  location
) => {
  try {
    const locationFilter = {
      address: location,
    };

    const jobQuery = {
      locationFilters: [locationFilter],
    };

    if (companyName) {
      jobQuery.companyNames = [companyName];
    }

    const request = {
      parent: `projects/${PROJECT_ID}`,
      resource: {
        jobQuery: jobQuery,
        requestMetadata: REQUEST_META_DATA,
        searchMode: 'JOB_SEARCH',
        enable_broadening: true,
      },
    };

    const result = await jobServiceClient.projects.jobs.search(request);

    console.log(JSON.stringify(result.data));
  } catch (e) {
    console.error(e);
    throw e;
  }
};

Ruby

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

# project_id      = "Id of the project."
# company_name    = "The resource name of the company listing the job. The format is "projects/{project_id}/companies/{company_id}""
# city            = "Name of the city where we want to do the job search."
require "google/apis/jobs_v3"
# Instantiate the client
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 requestMetadata 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
location_filter = jobs::LocationFilter.new address: city
# Perform a search for analyst  related jobs
job_query = jobs::JobQuery.new location_filters: [location_filter],
                               company_names:    [company_name]

search_jobs_request = jobs::SearchJobsRequest.new request_metadata:  request_metadata,
                                                  job_query:         job_query,
                                                  search_mode:       "JOB_SEARCH",
                                                  enable_broadening: true

search_jobs_response = talent_solution_client.search_jobs project_id, search_jobs_request

puts search_jobs_response.to_json
search_jobs_response