自定义属性

Cloud Talent Solution 以开箱即用的方式提供了多种不同的职位属性,可以满足各种客户的需求。为了通过 Cloud Talent Solution 实现最佳性能,强烈建议您尽可能使用开箱即用的字段。

此外,Cloud Talent Solution 还提供用于存储常规信息的自定义属性。自定义属性用于提供更高的灵活性,以允许客户支持其业务逻辑。自定义属性会存储字符串或数值信息,用户可以设置适当的过滤器对搜索查询进行过滤。

自定义属性功能

  • 定义您自己的自定义字段名称:定义一则招聘信息的特定属性的名称。根据需要将此属性设置为可过滤或不可过滤。通常,如果界面需要 Cloud Talent Solution 未以开箱即用方式提供的可过滤属性,则可以使用 customAttribute 提供适当的过滤。
  • (不)区分大小写的搜索:各搜索请求可以指定针对所有自定义属性发起的搜索是否区分大小写。
  • 基于范围的过滤customAttribute 搜索过滤器可以过滤一系列指定的数值之间的招聘信息。例如,如果给定的 customAttribute 字段用于存储招聘信息的最低 GPA 要求,则 customAttribute 搜索过滤器可用于返回符合在特定最小 GPA 范围内、大于最小 GPA 值、小于最小 GPA 值等条件的招聘信息。
  • 跨字段过滤customAttribute 还为 Cloud Talent Solution 客户提供了通过定义表达式来过滤自定义属性组合的功能。例如,一家客户的业务逻辑表明,他们只想寻找帮助办理签证或支持远程办公的职位。客户将这两个字段存储在不同的 customAttribute 中。然后,客户可以使用一个定义必要逻辑的表达式来指定搜索过滤器。该系统仅支持 3 级嵌套表达式。

  • 关键字特定搜索:在相关公司的 keywordSearchableCustomAttributes 中指定特定的 customAttribute,以确保指定 customAttribute 中包含一个值的搜索请求返回 customAttribute 中包含此值的招聘信息。

  • 基于 SQL 的搜索customAttribute 允许您在搜索请求中定义布尔值式的表达式。Cloud Talent Solution 会自动解析这些表达式,将过滤器应用于搜索请求,并相应地返回结果。该系统仅允许 3 级嵌套式布尔值表达式,最多允许 2000 个字符。

  • 定义自定义直方图存储分区:自定义属性允许 Cloud Talent Solution 设置自定义存储分区,以计算直方图。 例如,您可以使用 customAttribute 存储最小 GPA 信息,然后根据此字段创建直方图。您可以进一步创建 3.0-3.5、3.51-4.0 等范围内的存储分区,将所有最小 GPA 分组到这些存储分区之内。

使用自定义属性

使用 customAttribute 字段(可与数值或字符串值一起使用)创建新招聘信息:

Go

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	"github.com/gofrs/uuid"
	talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
	money "google.golang.org/genproto/googleapis/type/money"
)

// createJobWithCustomAttributes creates a job with custom attributes.
func createJobWithCustomAttributes(w io.Writer, projectID, companyID, jobTitle string) (*talentpb.Job, error) {
	ctx := context.Background()

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

	// requisitionID shoud be the unique ID in your system
	requisitionID := fmt.Sprintf("job-with-custom-attribute-%s", uuid.Must(uuid.NewV4()).String())
	jobToCreate := &talentpb.Job{
		Company:       fmt.Sprintf("projects/%s/companies/%s", projectID, companyID),
		RequisitionId: requisitionID,
		Title:         jobTitle,
		ApplicationInfo: &talentpb.Job_ApplicationInfo{
			Uris: []string{"https://googlesample.com/career"},
		},
		Description:     "Design, devolop, test, deploy, maintain and improve software.",
		LanguageCode:    "en-US",
		PromotionValue:  2,
		EmploymentTypes: []talentpb.EmploymentType{talentpb.EmploymentType_FULL_TIME},
		Addresses:       []string{"Mountain View, CA"},
		CustomAttributes: map[string]*talentpb.CustomAttribute{
			"someFieldString": {
				Filterable:   true,
				StringValues: []string{"someStrVal"},
			},
			"someFieldLong": {
				Filterable: true,
				LongValues: []int64{900},
			},
		},
		CompensationInfo: &talentpb.CompensationInfo{
			Entries: []*talentpb.CompensationInfo_CompensationEntry{
				{
					Type: talentpb.CompensationInfo_BASE,
					Unit: talentpb.CompensationInfo_HOURLY,
					CompensationAmount: &talentpb.CompensationInfo_CompensationEntry_Amount{
						Amount: &money.Money{
							CurrencyCode: "USD",
							Units:        1,
						},
					},
				},
			},
		},
	}

	// Construct a createJob request.
	req := &talentpb.CreateJobRequest{
		Parent: fmt.Sprintf("projects/%s", projectID),
		Job:    jobToCreate,
	}

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

	fmt.Fprintf(w, "Created job with custom attributres: %q\n", resp.GetName())
	fmt.Fprintf(w, "Custom long field has value: %v\n", resp.GetCustomAttributes()["someFieldLong"].GetLongValues())

	return resp, nil
}

Java

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


import com.google.cloud.talent.v4.CreateJobRequest;
import com.google.cloud.talent.v4.CustomAttribute;
import com.google.cloud.talent.v4.Job;
import com.google.cloud.talent.v4.JobServiceClient;
import com.google.cloud.talent.v4.TenantName;
import java.io.IOException;

public class JobSearchCreateJobCustomAttributes {

  public static void createJob() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String tenantId = "your-tenant-id";
    String companyId = "your-company-id";
    String requisitionId = "your-unique-req-id";
    createJob(projectId, tenantId, companyId, requisitionId);
  }

  // Create Job with Custom Attributes.
  public static void createJob(
          String projectId,
          String tenantId,
          String companyId,
          String requisitionId)
          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);

      // Custom attribute can be string or numeric value, and can be filtered in search queries.
      // https://cloud.google.com/talent-solution/job-search/docs/custom-attributes
      CustomAttribute customAttribute = CustomAttribute.newBuilder()
              .addStringValues("Internship")
              .addStringValues("Apprenticeship")
              .setFilterable(true)
              .build();

      Job job =
              Job.newBuilder()
                      .setCompany(companyId)
                      .setTitle("Software Developer I")
                      .setDescription("This is a description of this <i>wonderful</i> job!")
                      .putCustomAttributes("FOR_STUDENTS", customAttribute)
                      .setRequisitionId(requisitionId)
                      .setLanguageCode("en-US")
                      .build();

      CreateJobRequest request =
              CreateJobRequest.newBuilder().setParent(parent.toString()).setJob(job).build();
      Job response = jobServiceClient.createJob(request);
      System.out.printf("Created job: %s\n", response.getName());
    }
  }
}

Node.js

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


const talent = require('@google-cloud/talent').v4;

/**
 * Create Job with Custom Attributes
 *
 * @param projectId {string} Your Google Cloud Project ID
 * @param tenantId {string} Identifier of the Tenantd
 */
function sampleCreateJob(
  projectId,
  tenantId,
  companyName,
  requisitionId,
  languageCode
) {
  const client = new talent.JobServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  // const companyName = 'Company name, e.g. projects/your-project/companies/company-id';
  // const requisitionId = 'Job requisition ID, aka Posting ID. Unique per job.';
  // const languageCode = 'en-US';
  const formattedParent = client.tenantPath(projectId, tenantId);
  const job = {
    company: companyName,
    requisitionId: requisitionId,
    languageCode: languageCode,
  };
  const request = {
    parent: formattedParent,
    job: job,
  };
  client
    .createJob(request)
    .then(responses => {
      const response = responses[0];
      console.log(`Created job: ${response.name}`);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

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


from google.cloud import talent
import six

def create_job(project_id, tenant_id, company_id, requisition_id):
    """Create Job with Custom Attributes"""

    client = talent.JobServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'
    # company_id = 'Company name, e.g. projects/your-project/companies/company-id'
    # requisition_id = 'Job requisition ID, aka Posting ID. Unique per job.'
    # language_code = 'en-US'

    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")
    if isinstance(company_id, six.binary_type):
        company_id = company_id.decode("utf-8")

    # Custom attribute can be string or numeric value,
    # and can be filtered in search queries.
    # https://cloud.google.com/talent-solution/job-search/docs/custom-attributes
    custom_attribute = talent.CustomAttribute()
    custom_attribute.filterable = True
    custom_attribute.string_values.append("Intern")
    custom_attribute.string_values.append("Apprenticeship")

    parent = f"projects/{project_id}/tenants/{tenant_id}"

    job = talent.Job(
        company=company_id,
        title="Software Engineer",
        requisition_id=requisition_id,
        description="This is a description of this job",
        language_code="en-us",
        custom_attributes={"FOR_STUDENTS": custom_attribute}
    )

    response = client.create_job(parent=parent, job=job)
    print(f"Created job: {response.name}")
    return response.name

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

# title = "Software Engineer"
# description = "This is a description of this <i>wonderful</i> job!"
# company_name = "Company name, e.g. projects/your-project/companies/company-id"
# requisition_id = "Job requisition ID, aka Posting ID. Unique per job."
# language_code = "en-US"
job = {
  title:          title,
  description:    description,
  company:        company_name,
  requisition_id: requisition_id,
  language_code:  language_code
}

response = job_service.create_job parent: parent, job: job
puts "Created job: #{response.name}"

C#

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

public static object CreateJobCustomAttributes(string projectId, string tenantId, string companyId, string requisitionId)
{
    JobServiceClient jobServiceClient = JobServiceClient.Create();
    TenantName tenantName = TenantName.FromProjectTenant(projectId, tenantId);

    // Custom attribute can be string or numeric value, and can be filtered in search queries.
    // https://cloud.google.com/talent-solution/job-search/docs/custom-attributes
    CustomAttribute customAttributes = new CustomAttribute
    {
        Filterable = true
    };
    customAttributes.StringValues.Add("Internship");
    customAttributes.StringValues.Add("Intern");
    customAttributes.StringValues.Add("Apprenticeship");

    Job job = new Job
    {
        Company = companyId,
        RequisitionId = requisitionId,
        Title = "Software Developer I",
        Description = "This is a description of this <i>wonderful</i> job!",
        LanguageCode = "en-US"
    };
    job.CustomAttributes.Add("FOR_STUDENTS", customAttributes);

    CreateJobRequest request = new CreateJobRequest
    {
        ParentAsTenantName = tenantName,
        Job = job
    };

    Job response = jobServiceClient.CreateJob(request);

    Console.WriteLine($"Created Job: {response.Name}");
    return 0;
}

默认情况下,searchJobssearchJobsForAlert 端点仅搜索开箱即用的字段。如果还需要搜索 customAttribute 字段,请使用 keywordSearchableJobCustomAttributes 字段来定义要搜索的自定义属性列表。

例如,如果招聘人员希望使用 customAttribute"customRequisitions"来存储特定雇主职位的雇用 ID,那么可以将 keywordSearchableJobCustomAttributes 设置为包含此字段,此时招聘人员对“ABC123”执行常规搜索时即可返回 customAttribute"customRequisitions"的值设置为“ABC123”的所有招聘信息。