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.
![](https://res.cloudinary.com/salesforcecodex/image/upload/v1616403260/lwc/PromtedSearchTerm_uzloir.jpg)
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.
![](https://res.cloudinary.com/salesforcecodex/image/upload/v1616403319/lwc/PromtedSearchTerm_Keywords_bryrcx.jpg)
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.
![](https://res.cloudinary.com/salesforcecodex/image/upload/v1616403400/lwc/searchterm1_rqvclr.jpg)
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.
![](https://res.cloudinary.com/salesforcecodex/image/upload/v1616403453/lwc/LightningKnowledgeComponent_b6prkp.jpg)
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:
![Custom LWC Search Component for Knowledge](https://res.cloudinary.com/salesforcecodex/image/upload/v1616411398/lwc/CustomKnowledgeComponent_zqfi0e.jpg)
References:
https://salesforcecodex.com/salesforce/custom-salesforce-knowledge-component-using-lwc/
https://salesforcecodex.com/salesforce/show-category-wise-knowledge-article-using-lwc/