自定义排名功能允许您引入自己的业务逻辑,来控制 Cloud Talent Solution 返回的招聘信息的排名。 在网站上执行搜索的求职者可以照常设置其搜索查询和其他过滤器,并且可以向搜索请求添加排名表达式。Cloud Talent Solution 会根据求职者定义的查询确定相关招聘信息,并根据自定义排名表达式对结果进行排名。随后,它会将此排名列表返回给您,以便您可以将其显示给求职者。另外还提供有关实施自定义排名的视频教程。
优势
自定义排名允许您控制结果的列示方式。使用自定义排名可以定义可分配给自定义属性的权重。您可以使用权重和自定义属性的组合来构建自定义排名表达式,以确定所返回列表中列表项的顺序。
自定义排名基于现有搜索服务。它会利用任何客户定义的自定义属性组合中提供的值。
用例示例
最终用户搜索“软件工程师”。 贵企业希望在搜索的返回列表中将“软件工程师”置于排名更加靠前的位置。利用自定义排名,即可为这些列表设置一个值,按照自定义排名表达式确定的顺序将其显示给最终用户。
例如,您有两份几乎相同的职位列表,招聘信息 A 的每次点击费用 (CPC) 值要高于招聘信息 B。您可以设置通过权重加以调整的 CPC 自定义属性排名,从而利用自定义排名提高招聘信息 A 的曝光率。
使用方法
自定义排名支持以下数学运算符:+
、-
、*
、/
、(
)
您可以使用自定义属性的字段名称和这些数学运算符,来定义自定义排名表达式。
例如,假设您有两个自定义属性:CPC 和新鲜度,新鲜度表示招聘信息发布至今的天数。您希望按 CPC 和新鲜度对招聘信息进行排名,其中 CPC 占排名的 75%,新鲜度占 25%。您可以按如下方式创建自定义排名表达式:
(0.75*CPC) + (0.25 *Freshness)
代码示例
以下示例使用两个自定义属性 cpc_value
和 freshness_value
创建一个自定义排名表达式。它将自定义排名表达式设置为 (cpc_value / 2) - freshness_value
。
Go
import (
"context"
"fmt"
"io"
talent "cloud.google.com/go/talent/apiv4beta1"
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",
}
resp, err := c.SearchJobs(ctx, req)
if err != nil {
return fmt.Errorf("SearchJobs: %v", err)
}
for _, job := range resp.GetMatchingJobs() {
fmt.Fprintf(w, "Job: %q\n", job.GetJob().GetName())
}
return nil
}
Java
如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库。
import com.google.cloud.talent.v4.Job;
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 java.io.IOException;
public class CustomRankingSearchJobs {
public static void searchCustomRankingJobs() throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String tenantId = "your-tenant-id";
searchCustomRankingJobs(projectId, tenantId);
}
// Search Jobs using custom rankings.
public static void searchCustomRankingJobs(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();
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).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
如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库。
const talent = require('@google-cloud/talent').v4;
/**
* Search Jobs using custom rankings
*
* @param projectId {string} Your Google Cloud Project ID
* @param tenantId {string} Identifier of the Tenantd
*/
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 importanceLevel = 'EXTREME';
const rankingExpression = '(someFieldLong + 25) * 0.25';
const customRankingInfo = {
importanceLevel: importanceLevel,
rankingExpression: rankingExpression,
};
const orderBy = 'custom_ranking desc';
const request = {
parent: formattedParent,
requestMetadata: requestMetadata,
customRankingInfo: customRankingInfo,
orderBy: orderBy,
};
client
.searchJobs(request)
.then(responses => {
const resources = responses[0];
for (const resource of resources.matchingJobs) {
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
如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库。
from google.cloud import talent
import six
def search_jobs(project_id, tenant_id):
"""Search Jobs using custom rankings"""
client = talent.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 = 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
)
importance_level = talent.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
results = []
request = talent.SearchJobsRequest(
parent=parent,
request_metadata=request_metadata,
custom_ranking_info=custom_ranking_info,
order_by=order_by
)
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
Ruby
如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库。
require "google/cloud/talent"
# Instantiate a client
job_service = Google::Cloud::Talent.job_service
# project_id = "Your Google Cloud Project ID"
# tenant_id = "Your Tenant ID (using tenancy is required)"
parent = job_service.tenant_path project: project_id, tenant: 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.
response = job_service.search_jobs parent: parent,
request_metadata: request_metadata,
custom_ranking_info: custom_ranking_info,
order_by: order_by
response.matching_jobs.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
C#
如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库。
public static object CustomRankingSearch(string projectId, string tenantId)
{
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
};
CustomRankingInfo customRankingInfo = new CustomRankingInfo
{
ImportanceLevel = ImportanceLevel.Extreme,
// Custom ranking supports math operators, and Field name can be CPC or Freshness
// https://cloud.google.com/talent-solution/job-search/docs/custom-ranking#how_to_use
RankingExpression = "(someFieldLong + 25) * 0.25"
};
string orderBy = "custom_ranking desc";
SearchJobsRequest request = new SearchJobsRequest
{
ParentAsTenantName = name,
CustomRankingInfo = customRankingInfo,
RequestMetadata = requestMetadata,
OrderBy = orderBy
};
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;
}