Service Portal: Change the sort order of search results [typeahead-search]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 08:36 AM
Hi everybody,
So I'm currently messing with a clone of the 'typeahead-search' widget as well as the Search bar on our main Service Portal. We just upgraded to New York, and the type ahead widget returns a lot of results that I need to sort.
Some other sources I've considered are listed below, but I can't quite find the solution I need:
- Adding a Table Source
- This community article on Portal Search Sources and modifying the typeahead-search widget
- Modifying 'glide.service_portal.default_search_sources' and reordering them
- Improving the search results
In the widget, I need to complete the sorting of the following:
- Service Catalog Items sort first [Order: 100]
- Record Producers, Requests, and so on
- Knowledge Base articles [Order: 200]
- Anything else [Order: 300]
I just need a little push or direction on how to corral the data in order, because I have a strong feeling that our end-users will increasingly send us tickets saying, "I can't find the 'xyz' form!" It will still be there, just not the first result...
Thank you for any advice!
- Labels:
-
Service Portal Development
- 3,630 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2020 12:46 AM
Hi Sean,
There is no way of defining the sort order as the results are returned by the search api.
To do this we have to sort the result and then return the object to the typeahead.
// Client script
// Define a result variable and an Order variable
$scope.result = [];
$scope.resultOrder = ['qa','sc','kb']; // desired order of the search sources
// Add the fllowing in the getResult function
c.getResults = function(query) {
..
return $http.post("/api/now/sp/search", payload).then(function(response) {
..
$scope.result = result.results.map(function(item) {
..
//Add the following line at the end of the map to set the sort order
item.order = $scope.resultOrder.indexOf(item.__search_source_id__);
return item;
});
// Sort the result
$scope.result.sort(function(a, b){
return a.order - b.order
});
return $scope.result;
});
}
Hope this helps 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2022 12:25 AM
Hello
Thanks
Viraj Deshmukh