Announcing the Global SNUG Board of Directors. Learn more here

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
chuck_warner
ServiceNow Employee
ServiceNow Employee

Ever wonder how ServiceNow decides what search items are suggested in the global text search field when you start typing? There are a couple of prevailing theories. The first is that data elves appear at midnight and begin furiously cobbling statistics together and then infuse them with pixie dust so that they are magically attached to the search box. Or it could just be a simple ol' scheduled job.

data_search.png

 

To begin, every text search a user does is captured in a table called text_search. And yes, this really is EVERY search; including those overly colorful search terms that your users think they are being funny with, or perhaps the user was having one of those slightly disgruntled sort of days and decide to take it out on your instance. Each night the "TS Search Stats" scheduled job (sys_trigger record) then calls our TSSearchStatistician java code to populate the ts_search_stats table. Now while you can take a look at the records that are in the text_search table you will not be able to see the records in ts_search_stats. We do that on purpose because we want to keep the magic alive. If we let you see all our secrets where would the mystery be?

 

The scheduled job begins by looking at all the records that fall into the stat search window, which is controlled by the glide.ts.search_stat_window system property. If there is no property in the instance or no value is specified for that property it defaults to 365 days. The job does an aggregate query within the date range and orders the results by search term and then adds records to the ts_search_stats table accordingly.

 

When your users type into the text search box it runs a search against the ts_search_stats table as follows:

 

  • The search_term column starts with the characters the user entered
  • The mean_hits column value is greater than zero

 

The results are then ordered by:

  • search_count
  • mean_hits
  • search_term
  • Listed by what the maximum # of choices is set to (glide.xmlhttp.max_choices system property).

 

And voila: search suggestions aplenty!. I still have not completely ruled out data elves but am waiting for the first ServiceNow system admin to post a selfie with one of them to the internet. Until then, I am going with dull scheduled job theory. Perhaps one of your admins will camp out by your instance overnight and make the discovery and join the ranks of those pursuing Big Foot, the Loch Ness Monster, and Elvis sightings. Nessie lives!

7 Comments