Salesforce Knowledge articles are used for documentation useful information about application process and usage. These articles can be categories using data categories and we can also set keywords for easy searching.
To add search keyword for any knowledge articles, we can use Promoted Search Term in Salesforce. This will associate keywords in knowledge article. We can add Promoted Search Term related list in knowledge article page layout.
Once we add related list, we can add search term in knowledge articles. As example, we have added four search terms apex, canvas, card and hello in one article.
Now, let us see, how these search terms can be used in searching articles. These search term can be searched from Global Search, Knowledge component and Custom lightning component.
Standard Search Component:
Global Search:
As Hello is added in search term in knowledge so when we search that word, it will show that knowledge article.
Knowledge Component:
We can search knowledge articles using Knowledge component as well. This component should be added on page layout by Lightning app builder or dynamic forms.
After adding on page, we can search text using search text bar in Knowledge component.
Search Article using Custom Component:
If we want to use custom component to show search knowledge articles, then we have to use SearchPromotionRule sObject. This object has all search term information added for article. To create a search component, let us first create apex class which will search articles, based on given search keyword.
Apex Code for Searching Articles
Based on search data show all articles on LWC component. For demo purpose, we can use lightning-datatable to show articles.
LWC Code for using above Apex and showing result
Demo Page:
References:
https://salesforcecodex.com/salesforce/custom-salesforce-knowledge-component-using-lwc/
https://salesforcecodex.com/salesforce/show-category-wise-knowledge-article-using-lwc/