"Contains"-Search in Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 07:53 AM
Hi Folks,
we have the requirement to implement a "contains"-search in Service Portal. For example, if someone is searching for an Apple device, he should also get the results when only typing "pple":
In the forum, I already read that this could be achievable by modifying the Search Sources (Service Portal -> Search Sources), but unfortunately it didn`t work out for me.
I imagine, such a demand might be a common use case, so it`d be nice, if someone shares his code or other solution ideas.
Thanks in advance!
- Labels:
-
Search
-
Service Catalog
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 09:37 AM
Hi David
I'm not confident enough to recommend you go ahead and implement this, as I suspect this is not OOTB functionality for a reason (or possibly several) ..
However, I noticed you get the desired functionality by adding * to the beginning of your search and so you could look at updating the "Catalogs" Search Source Data fetch script to something like this:
var indexGroup = (typeof indexGroup !== "undefined") ? indexGroup : "portal_index_group";
(function(query, indexGroup) {
query = '*' + query; //add contains operator to the users search term
var results = [];
- Matt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 02:14 PM
Hi Matt,
thanks for your answer. It already helped to improve the results.
Unfortunately there`s still one flaw: this contains-method somehow doesn`t work, if one already knows the correct start of a word/meta tag.
So in terms of the example above, it works when typing "Apple" and even "pple", but it doesn`t work for "App" or "Appl".
Do you have an idea, why this might be?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2020 12:58 AM
Hi David
I did a bit more digging and I think this may work:
var indexGroup = (typeof indexGroup !== "undefined") ? indexGroup : "portal_index_group";
(function(query, indexGroup) {
query = '*' + query + ' | ' + query;
It seems * is expecting a character to appear before the search term which is why App and Apple was not matching anything.
- Matt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2020 10:03 AM
Hi Matt,
thanks again for your reply.
The new code didn`t change much in terms of results, but your idea inspired me to experiment a bit more.
Right now, I`m using this:
var indexGroup = (typeof indexGroup !== "undefined") ? indexGroup : "portal_index_group";
(function(query, indexGroup) {
//enable "contains"-query
query = '*' + query + '*';
var results = [];
Now it also finds terms expanding the query, at least in most cases. The "Apple"-example still doesn`t work, but strangely all of our actual services can be found.
It might not be a ServiceNow Best Practice, but it feels like this code plus some decent meta-tags lead to a pretty close "contains"-search.