Custom Ranking

The custom ranking feature allows you to introduce your own business logic to control the ranking of jobs returned by Cloud Talent Solution. A job seeker searching on a site can set their search query and other filters as always, and you can add a ranking expression to the search request. Cloud Talent Solution determines the relevant jobs to the query defined by the job seeker, and ranks the results based on the custom ranking expression. This ranked list is then returned to you so that you can display it to the job seeker.

Benefits

Custom ranking allows you to control on how the results are listed. Using a custom ranking lets you define weights you can assign to custom attributes. You can use a combination of weights and custom attributes to build a custom ranking expression to determine the order the returned listings.

Custom ranking is built on the existing search service. It leverages the values provided in any customer-defined combination of the custom attributes.

Example use case

The end user searches for "Software Engineer". Your business wants to showcase higher return listings for "Software Engineer". Using Custom Ranking allows you to place a value on these listings and show them to the end user in the order determined by the custom ranking expression.

For example, you have two nearly identical job listings with job-A having a higher cost per click (CPC) value than job-B. You can use custom ranking to increase the visibility of job-A by setting the adjusting the ranking of the CPC custom attribute with weights.

How to use

Custom ranking supports the following mathematical operators: +, -, *, /, (, )

You can use the field names of custom attributes and these mathematical operators to define a custom ranking expression.

For example, consider that you have two custom attributes: CPC and freshness, where freshness is the number of days since the job was posted. You want to rank jobs by CPC and freshness, where CPC counts for 75% of the ranking and freshness counts for 25%. You can create a custom ranking expression as follows:

(0.75*CPC) + (0.25 *Freshness)

Code Sample

The following example creates a custom ranking expression using two custom attributes, cpc_value and freshness_value. It sets the custom ranking expression to (cpc_value / 2) - freshness_value.

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"
)

// customRankingSearch searches for jobs based on custom ranking.
func customRankingSearch(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("taleng.NewJobClient: %v", 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",
		},
		JobQuery: &talentpb.JobQuery{
			Companies: []string{fmt.Sprintf("projects/%s/companies/%s", projectID, companyID)},
		},
		// More info on customRankingInfo.
		// https://godoc.org/google.golang.org/genproto/googleapis/cloud/talent/v4beta1#SearchJobsRequest_CustomRankingInfo
		CustomRankingInfo: &talentpb.SearchJobsRequest_CustomRankingInfo{
			ImportanceLevel:   talentpb.SearchJobsRequest_CustomRankingInfo_EXTREME,
			RankingExpression: "(someFieldLong + 25) * 0.25",
		},
		OrderBy: "custom_ranking desc",
	}

	it := c.SearchJobs(ctx, req)

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

Java

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

/*
 * Please include the following imports to run this sample.
 *
 * 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.SearchJobsRequest.CustomRankingInfo;
 * import com.google.cloud.talent.v4beta1.SearchJobsRequest;
 * import com.google.cloud.talent.v4beta1.SearchJobsResponse.MatchingJob;
 * import com.google.cloud.talent.v4beta1.TenantName;
 * import com.google.cloud.talent.v4beta1.TenantOrProjectName;
 */

/**
 * Search Jobs using custom rankings
 *
 * @param projectId Your Google Cloud Project ID
 * @param tenantId Identifier of the Tenantd
 */
public static void sampleSearchJobs(String projectId, String tenantId) {
  try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
    // projectId = "Your Google Cloud Project ID";
    // tenantId = "Your Tenant ID (using tenancy is optional)";
    TenantOrProjectName 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();
    SearchJobsRequest.CustomRankingInfo.ImportanceLevel importanceLevel =
        SearchJobsRequest.CustomRankingInfo.ImportanceLevel.EXTREME;
    String rankingExpression = "(someFieldLong + 25) * 0.25";
    SearchJobsRequest.CustomRankingInfo customRankingInfo =
        SearchJobsRequest.CustomRankingInfo.newBuilder()
            .setImportanceLevel(importanceLevel)
            .setRankingExpression(rankingExpression)
            .build();
    String orderBy = "custom_ranking desc";
    SearchJobsRequest request =
        SearchJobsRequest.newBuilder()
            .setParent(parent.toString())
            .setRequestMetadata(requestMetadata)
            .setCustomRankingInfo(customRankingInfo)
            .setOrderBy(orderBy)
            .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());
    }
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);
  }
}

PHP

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

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

use Google\Cloud\Talent\V4beta1\JobServiceClient;
use Google\Cloud\Talent\V4beta1\RequestMetadata;
use Google\Cloud\Talent\V4beta1\SearchJobsRequest_CustomRankingInfo;
use Google\Cloud\Talent\V4beta1\SearchJobsRequest_CustomRankingInfo_ImportanceLevel;

/**
 * Search Jobs using custom rankings.
 *
 * @param string $projectId Your Google Cloud Project ID
 * @param string $tenantId  Identifier of the Tenantd
 */
function sampleSearchJobs($projectId, $tenantId)
{

    $jobServiceClient = new JobServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID (using tenancy is optional)';
    $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);
    $importanceLevel = SearchJobsRequest_CustomRankingInfo_ImportanceLevel::EXTREME;
    $rankingExpression = '(someFieldLong + 25) * 0.25';
    $customRankingInfo = new SearchJobsRequest_CustomRankingInfo();
    $customRankingInfo->setImportanceLevel($importanceLevel);
    $customRankingInfo->setRankingExpression($rankingExpression);
    $orderBy = 'custom_ranking desc';

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

}

Python

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


from google.cloud import talent_v4beta1
from google.cloud.talent_v4beta1 import enums
import six


def sample_search_jobs(project_id, tenant_id):
    """Search Jobs using custom rankings"""

    client = talent_v4beta1.JobServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'

    if isinstance(project_id, six.binary_type):
        project_id = project_id.decode('utf-8')
    if isinstance(tenant_id, six.binary_type):
        tenant_id = tenant_id.decode('utf-8')
    parent = client.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
    }
    importance_level = enums.SearchJobsRequest.CustomRankingInfo.ImportanceLevel.EXTREME
    ranking_expression = '(someFieldLong + 25) * 0.25'
    custom_ranking_info = {
        'importance_level': importance_level,
        'ranking_expression': ranking_expression
    }
    order_by = 'custom_ranking desc'

    # Iterate over all results
    for response_item in client.search_jobs(
            parent,
            request_metadata,
            custom_ranking_info=custom_ranking_info,
            order_by=order_by):
        print('Job summary: {}'.format(response_item.job_summary))
        print('Job title snippet: {}'.format(response_item.job_title_snippet))
        job = response_item.job
        print('Job name: {}'.format(job.name))
        print('Job title: {}'.format(job.title))


Ruby

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


 # Search Jobs using custom rankings
 #
 # @param project_id {String} Your Google Cloud Project ID
 # @param tenant_id {String} Identifier of the Tenantd
def sample_search_jobs(project_id, tenant_id)
  # 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)"
  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
  }
  importance_level = :EXTREME
  ranking_expression = "(someFieldLong + 25) * 0.25"
  custom_ranking_info = { importance_level: importance_level, ranking_expression: ranking_expression }
  order_by = "custom_ranking desc"

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

Czy ta strona była pomocna? Podziel się z nami swoją opinią:

Wyślij opinię na temat...

Job Search documentation