Schnellstart: Suche

Mit Cloud Talent Solution können Sie nach derzeit aktiven Jobs suchen, die Sie im Cloud Talent Solution-System veröffentlicht haben. Wenn Sie Suchanfragen stellen können, müssen Sie das Job-Analyse-Framework implementieren und Clientereignisse implementieren. Dieses spielt für den Erfolg von Cloud Talent Solution eine zentrale Rolle und schlägt sich direkt in verbesserten Suchergebnissen nieder. Video-Tutorials und interaktive Codelabs sind ebenfalls verfügbar .

Histogramm der Anzahl von Jobs nach einem bestimmten Feld abrufen

Die Search API gibt auch ein Histogramm aller relevanten Jobs zurück, die in Cloud Talent Solution indexiert sind und mit den Filtern der Suchanfrage übereinstimmen. Nachdem Sie jetzt die Suchergebnisse erhalten haben, können Sie die Anzahl der Jobs nach unterschiedlichen Attributen abrufen. Verwenden Sie hierfür die Histogram API.

Go

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	"google.golang.org/api/iterator"
	talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
)

// histogramSearch searches for jobs with histogram queries.
func histogramSearch(w io.Writer, projectID, companyID string) error {
	ctx := context.Background()

	// Initialize a jobService client.
	c, err := talent.NewJobClient(ctx)
	if err != nil {
		fmt.Printf("talent.NewJobClient: %v\n", err)
		return err
	}

	// Construct a searchJobs request.
	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",
		},
		HistogramQueries: []*talentpb.HistogramQuery{
			{
				// More info on histogram facets, constants, and built-in functions:
				// https://godoc.org/google.golang.org/genproto/googleapis/cloud/talent/v4beta1#SearchJobsRequest
				HistogramQuery: "count(base_compensation, [bucket(12, 20)])",
			},
		},
	}
	if companyID != "" {
		req.JobQuery = &talentpb.JobQuery{
			CompanyNames: []string{fmt.Sprintf("projects/%s/companies/%s", projectID, companyID)},
		}
	}

	it := c.SearchJobs(ctx, req)

	for {
		resp, err := it.Next()
		if err == iterator.Done {
			return nil
		}
		if err != nil {
			fmt.Printf("it.Next: %v\n", err)
			return err
		}
		fmt.Fprintf(w, "Job: %q\n", resp.Job.GetName())
	}
}

Java

Weitere Informationen zum Installieren und Erstellen eines Cloud Talent Solution-Clients finden Sie unter Cloud Talent Solution-Clientbibliotheken.


import com.google.cloud.talent.v4beta1.HistogramQuery;
import com.google.cloud.talent.v4beta1.Job;
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 java.io.IOException;

public class HistogramSearchJobs {

  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";
    String query = "count(base_compensation, [bucket(12, 20)])";
    searchJobs(projectId, tenantId, query);
  }

  // Search Jobs with histogram queries.
  public static void searchJobs(String projectId, String tenantId, String query)
      throws IOException {
    try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
      TenantName parent = TenantName.of(projectId, tenantId);

      String domain = "http://www.jobUrl.com";
      String sessionId = "Hashed session identifier";
      String userId = "Hashed user identifier";
      RequestMetadata requestMetadata =
          RequestMetadata.newBuilder()
              .setDomain(domain)
              .setSessionId(sessionId)
              .setUserId(userId)
              .build();
      HistogramQuery histogramQueriesElement =
          HistogramQuery.newBuilder().setHistogramQuery(query).build();
      SearchJobsRequest request =
          SearchJobsRequest.newBuilder()
              .setParent(parent.toString())
              .setRequestMetadata(requestMetadata)
              .addHistogramQueries(histogramQueriesElement)
              .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());
      }
    }
  }
}

PHP

Weitere Informationen zum Installieren und Erstellen eines Cloud Talent Solution-Clients finden Sie unter Cloud Talent Solution-Clientbibliotheken.

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

use Google\Cloud\Talent\V4beta1\JobServiceClient;
use Google\Cloud\Talent\V4beta1\HistogramQuery;
use Google\Cloud\Talent\V4beta1\RequestMetadata;

/**
 * Search Jobs with histogram queries.
 *
 * @param string $query Histogram query
 *                      More info on histogram facets, constants, and built-in functions:
 *                      https://godoc.org/google.golang.org/genproto/googleapis/cloud/talent/v4beta1#SearchJobsRequest
 */
function sampleSearchJobs($projectId, $tenantId, $query)
{

    $jobServiceClient = new JobServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID (using tenancy is optional)';
    // $query = 'count(base_compensation, [bucket(12, 20)])';
    $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);
    $histogramQueriesElement = new HistogramQuery();
    $histogramQueriesElement->setHistogramQuery($query);
    $histogramQueries = [$histogramQueriesElement];

    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

Weitere Informationen zum Installieren und Erstellen eines Cloud Talent Solution-Clients finden Sie unter Cloud Talent Solution-Clientbibliotheken.


# Search Jobs with histogram queries
#
# @param query {String} Histogram query
# More info on histogram facets, constants, and built-in functions:
# https://godoc.org/google.golang.org/genproto/googleapis/cloud/talent/v4beta1#SearchJobsRequest
def sample_search_jobs project_id, tenant_id, query
  # 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)"
  # query = "count(base_compensation, [bucket(12, 20)])"
  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
  }
  histogram_queries_element = { histogram_query: query }
  histogram_queries = [histogram_queries_element]

  # Iterate over all results.
  job_client.search_jobs(formatted_parent, request_metadata, histogram_queries: histogram_queries).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#

Weitere Informationen zum Installieren und Erstellen eines Cloud Talent Solution-Clients finden Sie unter Cloud Talent Solution-Clientbibliotheken.

public static object HistogramSearchJobs(string projectId, string tenantId, string query)
{
    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
    };

    // Examples and formats are explained in the following link:
    // https://cloud.google.com/talent-solution/job-search/docs/reference/rest/v4beta1/projects.tenants.jobs/search#body.request_body.FIELDS.histogram_queries
    HistogramQuery histogramQuery = new HistogramQuery
    {
        HistogramQuery_ = query
    };

    SearchJobsRequest request = new SearchJobsRequest
    {
        ParentAsTenantName = name,
        RequestMetadata = requestMetadata,
    };
    request.HistogramQueries.Add(histogramQuery);

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

In diesem Fall erhalten Sie die Anzahl aller Jobs im System, die von den angegebenen Filtern akzeptiert werden, für die angegebenen Attribute CATEGORY und CITY.

Autocomplete API verwenden, um vorgeschlagene Jobtitel abzurufen

Die Autocomplete API schlägt dem Jobsuchenden eventuell interessante Job- oder Unternehmenstitel anhand dessen vor, was er bereits eingegeben hat. Hiermit können Sie potenzielle Ergebnisse in der Suchleiste Ihrer UI automatisch vervollständigen.

Go

Weitere Informationen zum Installieren und Erstellen eines Cloud Talent Solution-Clients finden Sie unter Cloud Talent Solution-Clientbibliotheken.

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
)

// jobTitleAutoComplete suggests the job titles of the given
// company identifier on query.
func jobTitleAutocomplete(w io.Writer, projectID, query string) (*talentpb.CompleteQueryResponse, error) {
	ctx := context.Background()

	// Initialize a completionService client.
	c, err := talent.NewCompletionClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("talent.NewCompletionClient: %v", err)
	}

	// Construct a completeQuery request.
	req := &talentpb.CompleteQueryRequest{
		Parent:        fmt.Sprintf("projects/%s", projectID),
		Query:         query,
		LanguageCodes: []string{"en-US"},
		PageSize:      5, // Number of completion results returned.
		Scope:         talentpb.CompleteQueryRequest_PUBLIC,
		Type:          talentpb.CompleteQueryRequest_JOB_TITLE,
	}

	resp, err := c.CompleteQuery(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("CompleteQuery(%s): %v", query, err)
	}

	fmt.Fprintf(w, "Auto complete results:")
	for _, c := range resp.GetCompletionResults() {
		fmt.Fprintf(w, "\t%v\n", c.Suggestion)
	}

	return resp, nil
}

Java

Weitere Informationen zum Installieren und Erstellen eines Cloud Talent Solution-Clients finden Sie unter Cloud Talent Solution-Clientbibliotheken.


import com.google.cloud.talent.v4beta1.CompleteQueryRequest;
import com.google.cloud.talent.v4beta1.CompleteQueryResponse;
import com.google.cloud.talent.v4beta1.CompletionClient;
import com.google.cloud.talent.v4beta1.TenantName;
import java.io.IOException;

public class JobSearchAutoCompleteJobTitle {

  public static void completeQuery() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String tenantId = "your-tenant-id";
    String query = "your-query-for-job-title";
    completeQuery(projectId, tenantId, query);
  }

  // Complete job title given partial text (autocomplete).
  public static void completeQuery(String projectId, String tenantId, String query)
      throws IOException {
    try (CompletionClient completionClient = CompletionClient.create()) {
      TenantName parent = TenantName.of(projectId, tenantId);
      CompleteQueryRequest request =
          CompleteQueryRequest.newBuilder()
              .setParent(parent.toString())
              .setQuery(query)
              .setPageSize(5) // limit for number of results
              .addLanguageCodes("en-US") // language code
              .build();
      CompleteQueryResponse response = completionClient.completeQuery(request);
      for (CompleteQueryResponse.CompletionResult result : response.getCompletionResultsList()) {
        System.out.printf("Suggested title: %s\n", result.getSuggestion());
        // Suggestion type is JOB_TITLE or COMPANY_TITLE
        System.out.printf("Suggestion type: %s\n", result.getType());
      }
    }
  }
}

PHP

Weitere Informationen zum Installieren und Erstellen eines Cloud Talent Solution-Clients finden Sie unter Cloud Talent Solution-Clientbibliotheken.

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

use Google\Cloud\Talent\V4beta1\CompletionClient;

/**
 * Complete job title given partial text (autocomplete).
 *
 * @param string $projectId Your Google Cloud Project ID
 * @param string $tenantId  Identifier of the Tenantd
 */
function sampleCompleteQuery($projectId, $tenantId, $query, $numResults, $languageCode)
{

    $completionClient = new CompletionClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID (using tenancy is optional)';
    // $query = '[partially typed job title]';
    // $numResults = 5;
    // $languageCode = 'en-US';
    $formattedParent = $completionClient->tenantName($projectId, $tenantId);
    $languageCodes = [$languageCode];

    try {
        $response = $completionClient->completeQuery($formattedParent, $query, $numResults, ['languageCodes' => $languageCodes]);
        foreach ($response->getCompletionResults() as $result) {
            printf('Suggested title: %s'.PHP_EOL, $result->getSuggestion());
            // Suggestion type is JOB_TITLE or COMPANY_TITLE
            printf('Suggestion type: %s'.PHP_EOL, CompleteQueryRequest_CompletionType::name($result->getType()));
        }
    } finally {
        $completionClient->close();
    }

}

Ruby

Weitere Informationen zum Installieren und Erstellen eines Cloud Talent Solution-Clients finden Sie unter Cloud Talent Solution-Clientbibliotheken.


# Complete job title given partial text (autocomplete)
#
# @param project_id {String} Your Google Cloud Project ID
# @param tenant_id {String} Identifier of the Tenantd
def sample_complete_query project_id, tenant_id, query, num_results, language_code
  # Instantiate a client
  completion_client = Google::Cloud::Talent::Completion.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  # tenant_id = "Your Tenant ID (using tenancy is optional)"
  # query = "[partially typed job title]"
  # num_results = 5
  # language_code = "en-US"
  formatted_parent = completion_client.class.tenant_path(project_id, tenant_id)
  language_codes = [language_code]

  response = completion_client.complete_query(formatted_parent, query, num_results, language_codes: language_codes)
  response.completion_results.each do |result|
    puts "Suggested title: #{result.suggestion}"
    # Suggestion type is JOB_TITLE or COMPANY_TITLE
    puts "Suggestion type: #{result.type}"
  end
end

C#

Weitere Informationen zum Installieren und Erstellen eines Cloud Talent Solution-Clients finden Sie unter Cloud Talent Solution-Clientbibliotheken.

public static object CompleteQuery(string projectId, string tenantId, string query)
{
    CompletionClient completionClient = CompletionClient.Create();
    TenantName tenant = TenantName.FromProjectTenant(projectId, tenantId);
    CompleteQueryRequest request = new CompleteQueryRequest
    {
        ParentAsTenantName = tenant,
        Query = query, // partial text for job title
        PageSize = 5, // limit for number of results
        LanguageCodes = { "en-US" } // language code
    };
    var response = completionClient.CompleteQuery(request);
    foreach (var result in response.CompletionResults)
    {
        Console.WriteLine($"Suggested title: {result.Suggestion}");
        // Suggestion type is JOB_TITLE or COMPANY_TITLE
        Console.WriteLine($"Suggestion type: {result.Type}");
    }

    return 0;
}