Support Article
Custom sorting on Knowledge Management(KM) Search
SA-37168
Summary
When the user search in Knowledge Management portal with some specific key words Knowledge contents are shown in the search results. However these search results not arranged in an orderly fashion. The search result set comprise of a set of contents which have the search keyword either in their title , article content or in the associated tags. The user wants the contents fetched should be sorted in a way where the contents(articles) with the search keyword in their title will appear first. The KC items returned as serach results are required, shown below :
- Title first
- Content
- Tags
Error Messages
Not Applicable
Steps to Reproduce
- Create some Knowlege Contents and publish them from the Knowledge Management portal
- The CPM interaction portal.
- Click the help icon.
- In the pop up window search with a Keyword.
- Check the sorting of the Knowledge contents returned as search results.
Root Cause
Tracing down the activity stack shows that the results(KC items) are fetched using the elastic search(ES).
Thus ES will not return the result by grouping them with the article title , then the article content and so on.
Also a seperate search is made to find KC objects which have the search keyword present in their tags.
Thus the final search result is a mixture of all the objects with out any orderly fashion of arrangment.
Resolution
This can be achieved through a custom logic in theRULE-OBJ-ACTIVITY @baseclass.KMSearchRD activity rule. This is a Pega OOTB activity which is available for cuistomization.
The following approach can be taken :-
- Scan through the full resultset
- Copy the rows which contains the keyword in their title.
- Next, append the remaining rows which do not contain the search keyword in their title.
- The final page (pySearchResultsFiltered in this case) will have the sorted results.
A custom solution looks like this :-
Evaluate Expression [@String.contains(.ArticleTitle,param.searchText)]
pxResults(1) | True | Page-Copy | Temp. pxResults(<APPEND)>) | Temp. pxResults(1) |
pxResults(2) | False | Temp. pxResults(2) | ||
pxResults(3) | True | Page-Copy | Temp. pxResults(<APPEND)>) | Temp. pxResults(3) |
pxResults(4) | True | Page-Copy | Temp. pxResults(<APPEND)>) | Temp. pxResults(4) |
pxResults(5) | False | Temp. pxResults(5) |
Changes in the @baseclass.KMSearchRD activity :-
In the below screenshot Step no 14 , 15 , 16 and 18 are introduced for this custom solution.
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/11493295385592.jpg)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/21493295399918.jpg)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/31493295411254.jpg)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/41493295419925.jpg)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/51493295429948.jpg)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/61493295459960.jpg)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/71493295477913.jpg)
The results are after applying the above changes :-
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/r11493295553381.jpg)
![](https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/r21493295572740.jpg)
Published May 6, 2017 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.