Full Text Searches in Service Portal

serviceportal Service Portal

In the stock Service Portal it asks the user “How can we help” and then provides the user with a big search input. This implies that the user could enter a sentence or phrase such as “reset my password” to answer the question, however this will rarely deliver the correct results.

ServiceNow provides several search operators for performing full text searches with GlideRecord using ServiceNow’s Zing search engine. However the stock widgets in Service Portal are hardcoded to use 123TEXTQUERY321” which works great for single word searches but not so much for searches containing multiple words or phrases. In this example, the simple addition of the word “my” prevented the user from finding the “Reset Password” item.

To improve the search results, let’s take a quick look at some of the other options available.

Search OperatorDescription
IR_AND_QUERYDisplay results with exact matches of all terms only (Same as 123TEXTQUERY321)
IR_OR_QUERYDisplay results with any matches of any terms.
IR_AND_OR_QUERYFirst display results with exact matches of all terms, then display results with any matches of any terms

Of the above, I recommend using IR_AND_OR_QUERY as this will return the best results across all combinations of searches. When performing a full text search, ServiceNow also adds an additional property to the GlideRecord called “ir_query_score” which contains the relevance score calculated by the system. Administrators can control the scoring for each field in a table with the ts_weight attribute.

Here is a quick example of how to search the Service Catalog and return results ordered by relevancy:

For further reading, check out:

https://codecreative.io/servicenow/gliderecord-full-text-search-explained
https://codecreative.io/servicenow/how-to-do-full-text-search-with-gliderecord
http://wiki.servicenow.com/index.php?title=Administering_Zing_Text_Search

 

21 comments

  1. Thanks Nathan Does this still leverage the existing text indexes that Zing search relies on? It’s just changing the operator, yes?

    1. Hadyn, yes exactly. It’s still using Zing and the text indexes, it’s just using a different operator which greatly improves the search results.

  2. How does it differ from what ServiceNow offers OOB? It has Contextual Search for Service Portal too…..

    1. As mentioned above, all the OOB widgets use “123TEXTQUERY321” which does not search multiple words or phrases very well. Contextual search is a completely different widget, and will not be fully supported until Jakarta.

  3. Hello Nathan,

    Is there a way to make the “typeahead” work with multiple catalogs and knowledge bases? I know there a few examples in share but they only work once you click enter on the search page. I want to show either catalogs or documents on the typeahead while am writing something. Am on Helsinki. Anything would be appreciated.

    1. Istanbul certainly simplifies this for you with Search Sources, however for Helsinki I would just recommend cloning and modifying the Typeahead widget. It’s just using GlideRecord so it should not be too difficult.

    1. In Helsinki it’s hard coded in to the widgets, in Istanbul it’s in the Search Sources. If you need additional help, feel free to email me.

      1. Hi Nathan,

        Could you point me out to the exact place (widget/Search Source) where I would change the search operator? We are in Jakarta.

        Thank you

      2. I know this was a while ago, but thank you for your response Nathan. I was able to fix this in the Service Catalog Search source and now users can search the popular phrase “Reset my password” with multiple results instead of nothing.

      3. Hey Nathan,

        By reading your post it sounds like this might solve my problem however how can I use this in an icon link widget where I am using a record producer under which for reference field I want this search result to happen. It would be appreciable if you help me where exactly am I supposed to write down this code

  4. Since we’re still using Hels, I had to update the Search widget directly. The one thing I’ve noticed is that it’s noticeably slower than it was before (like near instantaneous vs 2-3 second delay) when returning results, although the results are much better. Is that expected, or is something wrong?

  5. Hello Nathan,

    Is it possible to use the above-mentioned query on Service Portal’s record producer’s reference field where I keep writing any word and if that word is exactly matched in the name then that name would be displayed first and later other strings which contain the word typed in? I am working in London release. The reply is much appreciated.

  6. Hi Nathan,

    Is it possible to search with the half matched keywords (for instance, keyword ‘Windows’ is giving 5 results but, ‘wind’ is giving me no records found) in the Typeahead Search widget.

    1. In the search source, you can try adding an asterisk to the end of the search term, e.g.

      q = q + “*”;

  7. Hi Nathan,
    SN updated their Portal Search Sources to use API methods for search in recent Releases. Do you know if the OOTB API methods have been enhanced to use your suggested operands?

  8. Hi Nathan,

    In the recent Release SN has updated the portal search to use the API CatalogSearch instead of gliderecord. I did some testing and the API also use 123TEXTQUERY321. I was not able to view the API code, but I’m wondering if we could implement the enhancement you show in this article to the API?

    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *