﻿#### 

If we want to achieve relevant search results, we need to boost a Sitecore item based on keywords which are entered by user in the a search bar. In this article, I want to share an example of how we can boost results by the item Template Name.

```

public Lis<SearchResultItem> Search(string keyword)
        {
            var sparePartsIndex = ContentSearchManager.GetIndex("YOUR INDEX NAME");
            var sparePartsSearchContext = sparePartsIndex.CreateSearchContext();

            var predicateRoots = PredicateBuilder.True<SearchResultItem>();

            var configuration = GetSearchConfiguration(); //Method is implemented below

            //Here you can put your conditions

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                foreach (var boostingModel in configuration)
                {
                    if (boostingModel.Keywords.Contains(keyword))
                    {
                        predicateRoots =
                            predicateRoots.Or(
                                itm => (itm.TemplateName == boostingModel.TemplateName)
                                    .Boost(boostingModel.BoostValue));
                        predicateRoots =
                            predicateRoots.Or(itm => (itm.TemplateName != boostingModel.TemplateName).Boost(1f));
                    }
                }
            }

            var queryable = sparePartsSearchContext.GetQueryable<SearchResultItem>().Where(predicateRoots);

            var searchresults = queryable.GetResults();

            return searchresults.Hits.Select(x => x.Document).ToList();
        }

        public List<BoostingMode> GetSearchConfiguration()
        {
         //I’ve implemented an example of search configuration for boosting the search result. 
    //This configuration can be implemented in the Sitecore for being more flexible  
            var config = new List<BoostingModel>
            {
                new BoostingModel
                {
                    //If user enter “root” or “roots” keywords, we will boost an item         with the “Highlights Root” template name  
      Keywords = new List<string> {"root", "roots"},
                    TemplateName = "Highlights Root",
                    BoostValue = 3f
                    
                },
                new BoostingModel
                {
      //If user enter “high” or “Highlight” keywords, we will boost an item         with the “Highlight” template name  
                    Keywords = new List<string> { "high", "Highlight"},
                    TemplateName = "Highlight",
                    BoostValue = 5f
                }
            };

            return config;
        }

        public class BoostingModel
        {
            public List<string> Keywords { get; set; }
            public string TemplateName { get; set; }
            public float BoostValue { get; set; }
        }
          
```

The results would be similar to what is shown below:

![boost search template](https://www.brimit.com/-/media/images/blog/boostsearchtemplate.png?la=en&amp;hash=7B14D72B0338FC9DC4750C7D9A3A5F0D)

The code that is shown above is just a simple example of how we would boost an item using its template name. To make this work in a real production environment, you would need to take some time and adapt it into your infrastructure.

Did it work for you? [Tell us](https://www.brimit.com/contact-us "Comments on article") what you think!

###### Author

[!\[artsiom-photo\](https://www.brimit.com/-/jssmedia/feature/blogs/authors/artsiom-200.jpg?h=202&amp;iar=0&amp;w=200&amp;hash=41797D2540DF6EB6FDF558360F6F62B8)
Artsem Prashkovich
Sitecore MVP/ Solution Architect](https://www.brimit.com/blog/author?authors=Artsem%20Prashkovich)

#### More on Sitecore

[!\[How Vercel Will Help You Save Effort When Deploying Sophisticated Sitecore Projects\](https://www.brimit.com/-/jssmedia/project/brimit/blog/2024/vercel_cover-image.png)
#Guides#How-toDXPE-commerce
##### How Vercel Will Help You Save Effort When Deploying Sophisticated Sitecore Projects
Optimize and accelerate the development and deployment of complex multisite Sitecore projects.
Alexei Vershalovich on July 17, 2024](https://www.brimit.com/blog/how-vercel-will-help-you-save-effort-when-deploying-sophisticated-sitecore-projects)

[!\[Training Up Tomorrow's Sitecore MVPs: a Mentoring Success Story\](https://www.brimit.com/-/jssmedia/project/brimit/blog/2023/sitecore-mentoring---cover-image.png)
#How-toDXP
##### Training Up Tomorrow's Sitecore MVPs: a Mentoring Success Story
How to participate in the Sitecore Mentor program and help younger colleagues jump-start a career in Sitecore development.
Sergey Baranov on October 2, 2023](https://www.brimit.com/blog/training-up-tomorrows-sitecore-mvps)

[!\[Going Headless. Part 2: When a Headless CMS Is Your Best Bet (if you have Sitecore)\](https://www.brimit.com/-/jssmedia/project/brimit/blog/2022/headless/adobestock_456986731.jpg)
#How-toDXPE-commerce
##### Going Headless. Part 2: When a Headless CMS Is Your Best Bet (if you have Sitecore)
Discover how a headless CMS can benefit organizations that use Sitecore.
Daniil Raschupkin, Palina Trokhautsava on September 15, 2022](https://www.brimit.com/blog/going-headless-part-2-when-a-headless-cms-is-your-best-bet-if-you-have-sitecore)

![](https://bat.bing.net/action/0?ti=187017043&amp;tm=gtm002&amp;Ver=2&amp;mid=5946ce48-c7ad-4d51-8797-c9c16b4e7fcc&amp;bo=2&amp;gtm_tag_source=1&amp;pi=0&amp;lg=en-US&amp;sw=800&amp;sh=600&amp;sc=24&amp;nwd=1&amp;tl=Boosting%20a%20search%20result%20by%20Template%20Name&amp;kw=Sitecore,%20search,%20custom,%20Template,%20Name&amp;p=https%3A%2F%2Fwww.brimit.com%2Fblog%2Fboosting-search-result-template-name&amp;r=&amp;lt=261&amp;evt=pageLoad&amp;sv=2&amp;asc=D&amp;cdb=AQAY&amp;rn=358181)