chuck_warner
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
valerie_gallot
Giga Expert

Thank you for this interessant explanation! The "did you mean" feature does not work very well on my instance (data elves are lazy?). What would you suggest to "help" the scheduled job to find good suggestions? Should I try many searches to force the ts_search_stats to contain relevant terms?


Why is this table not visible for admin? It should have been helpful...


chuck_warner
ServiceNow Employee

Hello Valerie,



Sorry for the delay in getting back to you. I lost track of the notification over the Thanksgiving holiday. You can adjust the read access control for that table and check the admin overrides to give yourself read access. As to why your system is not giving the results you expect I would suggest you open an incident in HI for us to investigate.



Chuck


chuck_warner
ServiceNow Employee

Hello Steve,



All searches that are done are stored in text_search table which has a result column so you could reference that data to see everything that is being searched on where zero results were brought back. You could search where results value was zero and then group by the term.



Chuck


YamR6
Tera Contributor

How are the search results determined if no value is entered? When I click on an empty search box I am returned a list.


alan_lowrance
Mega Guru

Hi Chuck, is there an easy way to order everything on searches?   I want searches to always order things newest-oldest and everything in the system should have a created/updated date I could sort by.   If not, where do I tell it that I want the search results of Incidents to be ordered by Opened_At or whatever?


Chandu Telu
Tera Guru

Can we add Type-ahead suggestions to list view search filter  


find_real_file.png



Thanks


Chandu Telu


kenv
Kilo Expert