Custom sorting on Knowledge Management(KM) Search
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
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.
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.
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(3)||True||Page-Copy||Temp. pxResults(<APPEND)>)||Temp. pxResults(3)|
|pxResults(4)||True||Page-Copy||Temp. pxResults(<APPEND)>)||Temp. pxResults(4)|
Changes in the @baseclass.KMSearchRD activity :-
In the below screenshot Step no 14 , 15 , 16 and 18 are introduced for this custom solution.
The results are after applying the above changes :-