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 .

Java

To authenticate to CTS, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  /** Histogram search */ 
 public 
  
 static 
  
 void 
  
 histogramSearch 
 ( 
 String 
  
 companyName 
 ) 
  
 throws 
  
 IOException 
 , 
  
 InterruptedException 
  
 { 
  
 // 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" 
 ); 
  
 HistogramFacets 
  
 histogramFacets 
  
 = 
  
 new 
  
 HistogramFacets 
 () 
  
 . 
 setSimpleHistogramFacets 
 ( 
 Arrays 
 . 
 asList 
 ( 
 "COMPANY_ID" 
 )) 
  
 . 
 setCustomAttributeHistogramFacets 
 ( 
  
 Arrays 
 . 
 asList 
 ( 
  
 new 
  
 CustomAttributeHistogramRequest 
 () 
  
 . 
 setKey 
 ( 
 "someFieldName1" 
 ) 
  
 . 
 setStringValueHistogram 
 ( 
 true 
 ))); 
  
 // conducted. 
  
 SearchJobsRequest 
  
 searchJobsRequest 
  
 = 
  
 new 
  
 SearchJobsRequest 
 () 
  
 . 
 setRequestMetadata 
 ( 
 requestMetadata 
 ) 
  
 . 
 setSearchMode 
 ( 
 "JOB_SEARCH" 
 ) 
  
 . 
 setHistogramFacets 
 ( 
 histogramFacets 
 ); 
  
 if 
  
 ( 
 companyName 
  
 != 
  
 null 
 ) 
  
 { 
  
 searchJobsRequest 
 . 
 setJobQuery 
 ( 
 new 
  
 JobQuery 
 (). 
 setCompanyNames 
 ( 
 Arrays 
 . 
 asList 
 ( 
 companyName 
 ))); 
  
 } 
  
 SearchJobsResponse 
  
 searchJobsResponse 
  
 = 
  
 talentSolutionClient 
  
 . 
 projects 
 () 
  
 . 
 jobs 
 () 
  
 . 
 search 
 ( 
 DEFAULT_PROJECT_ID 
 , 
  
 searchJobsRequest 
 ) 
  
 . 
 execute 
 (); 
  
 Thread 
 . 
 sleep 
 ( 
 1000 
 ); 
  
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Histogram search results: %s\n" 
 , 
  
 searchJobsResponse 
 ); 
 } 
 

Python

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

Python

To authenticate to CTS, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  def 
  
 histogram_search 
 ( 
 client_service 
 , 
 company_name 
 ): 
 request_metadata 
 = 
 { 
 "user_id" 
 : 
 "HashedUserId" 
 , 
 "session_id" 
 : 
 "HashedSessionId" 
 , 
 "domain" 
 : 
 "www.google.com" 
 , 
 } 
 custom_attribute_histogram_facet 
 = 
 { 
 "key" 
 : 
 "someFieldName1" 
 , 
 "string_value_histogram" 
 : 
 True 
 , 
 } 
 histogram_facets 
 = 
 { 
 "simple_histogram_facets" 
 : 
 [ 
 "COMPANY_ID" 
 ], 
 "custom_attribute_histogram_facets" 
 : 
 [ 
 custom_attribute_histogram_facet 
 ], 
 } 
 request 
 = 
 { 
 "search_mode" 
 : 
 "JOB_SEARCH" 
 , 
 "request_metadata" 
 : 
 request_metadata 
 , 
 "histogram_facets" 
 : 
 histogram_facets 
 , 
 } 
 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 
 ) 
 
Create a Mobile Website
View Site in Mobile | Classic
Share by: