Histogram (v3)

You can get a histogram representation of the number of jobs associated with a given search. A search request, with histogram facets set, returns the search results and a count of all the jobs that match a particular query, broken down by the requested searchType.

For example, a histogram search could return the number of jobs per employment type (full-time, part-time, and so on) from a customer's set of jobs.

The Cloud Talent Solution Beta release (v3p1beta1) allows you to define histograms in a less structured, more flexible, and more intuitive way. The histogram representations do not change.

Benefits

The new structure of the histogram queries offers developers more intuitive ways of defining histogram requests, while also providing more clarity into the definition of buckets, ranges, etc.

Usage

The new histogram part of the search query replaces the old structured fields for defining the histogram.

Code Samples

The following code sample returns histogram results.

The histogramQuery field is now a single string field that is an expression that defines the histogram. For details on the functions available for histogram queries, see HistogramQuery.

Java

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


/**
 * New histogram search
 */
public static void newHistogramSearch(String companyName) throws IOException {
  // Make sure to set the requestMetadata the same as the associated search request
  RequestMetadata requestMetadata =
      new RequestMetadata()
          // Make sure to hash your userID
          .setUserId("HashedUserId")
          // Make sure to hash the sessionID
          .setSessionId("HashedSessionID")
          // Domain of the website where the search is conducted
          .setDomain(
              "www.google.com");

  HistogramQuery companyIdHistogramQuery = new HistogramQuery()
      .setHistogramQuery("count(company_id)");
  HistogramQuery customFieldHistogramQuery = new HistogramQuery()
      .setHistogramQuery("count(string_custom_attribute[\"someFieldName1\"])");

  // conducted.
  SearchJobsRequest searchJobsRequest =
      new SearchJobsRequest()
          .setRequestMetadata(requestMetadata)
          .setHistogramQueries(Arrays.asList(companyIdHistogramQuery, customFieldHistogramQuery));
  if (companyName != null) {
    searchJobsRequest.setJobQuery(new JobQuery().setCompanyNames(Arrays.asList(companyName)));
  }

  SearchJobsResponse searchJobsResponse =
      talentSolutionClient
          .projects()
          .jobs()
          .search(DEFAULT_PROJECT_ID, searchJobsRequest)
          .execute();

  System.out.println(searchJobsResponse);
}

Python

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

def new_histogram_search(client_service, company_name):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    company_id_histogram_query = {
        'histogram_query': 'count(company_id)'
    }
    custom_field_histogram_query = {
        'histogram_query': 'count(string_custom_attribute["someFieldName1"])'
    }
    request = {
        'search_mode': 'JOB_SEARCH',
        'request_metadata': request_metadata,
        'histogram_queries': [company_id_histogram_query, custom_field_histogram_query]
    }
    if company_name is not None:
        request.update({'job_query': {'company_names': [company_name]}})
    response = client_service.projects().jobs().search(
        parent=parent, body=request).execute()
    print(response)