- [Home page](https://www.brimit.com/)
- [Blog](https://www.brimit.com/blog)

# Boosting Search Results with a Template Name

[#How-to](https://www.brimit.com/blog?categories=#How-to) [DXP](https://www.brimit.com/blog?platforms=DXP)
[Artsem Prashkovich](https://www.brimit.com/blog/author?authors=Artsem%20Prashkovich) on October 13, 2017

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&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&iar=0&w=200&hash=41797D2540DF6EB6FDF558360F6F62B8)

Artsem Prashkovich

Sitecore MVP/ Solution Architect
[Artsem Prashkovich](https://www.brimit.com/blog/author?authors=Artsem%20Prashkovich)

###### More By Categories

[#Events](https://www.brimit.com/blog?categories=#Events) [#How-to](https://www.brimit.com/blog?categories=#How-to) [#News](https://www.brimit.com/blog?categories=#News) [#Guides](https://www.brimit.com/blog?categories=#Guides)

###### More by Platform

[Data and AI](https://www.brimit.com/blog?platforms=Data%20and%20AI) [DXP](https://www.brimit.com/blog?platforms=DXP) [E-commerce](https://www.brimit.com/blog?platforms=E-commerce) [Internet of Things](https://www.brimit.com/blog?platforms=Internet%20of%20Things) [Sales and marketing automation](https://www.brimit.com/blog?platforms=Sales%20and%20marketing%20automation)

#### 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-to DXP E-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
[How Vercel Will Help You Save Effort When Deploying Sophisticated Sitecore Projects](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-to DXP

##### 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
[Training Up Tomorrow's Sitecore MVPs: a Mentoring Success Story](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-to DXP E-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
[Going Headless. Part 2: When a Headless CMS Is Your Best Bet (if you have Sitecore)](https://www.brimit.com/blog/going-headless-part-2-when-a-headless-cms-is-your-best-bet-if-you-have-sitecore)
