1

I just created the site search module where I need to get all the pages that the user is looking for.

I'm able to get the item name when content matches the search term, But also I need the content field value for the description field.

I'm getting null value when I get that field, it is not stored ?

         var searchResults = context.GetQueryable<SearchResultItem>()
                           .Where(x => (x.Content.Contains(searchkey) || x.Name.Contains(searchkey)) && x.Path.Contains(pathToBeSearch))
                           .Where(x => x.Language == ConfigurationItem.Language.Name)
                           .Where(x => !excludeTempltes.Contains(x.TemplateName))
                           .GetResults().Hits.Select(h => h.Document).ToArray();

                            foreach (SearchResultItem item in searchResults)
                            {
                              searchdata.Page_Title = item.Name;
                              searchdata.Page_Description = item.Content;
                            }

1 Answer 1

1

_content field is not stored. It contains a lot of data from many Sitecore text fields (and media items content if it's extracted). You don't want to keep all of that inside Solr.

You can search using _content field like you do in your code:

.Where(x => (x.Content.Contains(searchkey) ...

but you should NOT try to get its value from the index like

var content = searchResultsItem.Content;

Instead get the value from the field of your search result item which stores description only, or use some other fields as a fallback. Or even get the item from Sitecore API and get what you need from the original item.

1
  • Thanks, looks cool. I will use Sitecore API to get the meta description value from that item.
    – Rajasekar
    Commented Mar 31, 2020 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.