1

Using Sitecore 10.2 with Solr 8.4.0.

I have Product pages which inherit from a template - Product Details.
This template has the following fields:

Title - Rich Text
Description - Rich Text
Category - Single Line  
Tags - Treelist  

I would like to perform a search for a term that can exist in Title or Description or Category.

In this Article which provides the basic steps to get started with Search, I see that it uses the Content field to search for the term.

But in my code, the Content property is null.
What should be configured & where, so that the Content property will include all text from Title & Description & Category

I have created a custom index and here is how the results are fetched.

public List<T> GetSearchResults<T>(string searchIndexName, string templateName, string searchTerm) where T : SearchResultItem
        {
            ///get the index
            ISearchIndex searchIndex = ContentSearchManager.GetIndex(searchIndexName);

            ///create a search context
            using (IProviderSearchContext context = searchIndex.CreateSearchContext())
            {
                try
                {
                    ///build the query
                    var query = PredicateBuilder.True<T>();

                    if (!string.IsNullOrWhiteSpace(templateName))
                    {
                        query = query.And(x => x.TemplateName.Equals(templateName, StringComparison.InvariantCultureIgnoreCase));
                    }

                    if (!string.IsNullOrWhiteSpace(searchTerm))
                    {
                        query = query.And(x => x.Content.Contains(searchTerm)); 
                    }

                    /// get results from this index based on query
                    IQueryable<T> results = context.GetQueryable<T>().Where(query);
                    return results != null ? results.ToList() : null;
                }
                catch (Exception)
                {
                    // ignored
                }

                return null;
            }
        }

custom index:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore role:require="Standalone or ContentDelivery or ContentManagement" search:require="solr">
    <contentSearch>      
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
          <index id="custom_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
            <param desc="name">$(id)</param>
            <param desc="core">custom_index</param>
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
            <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" />
            <strategies hint="list:AddStrategy">
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/manual" role:require="(ContentManagement and !Indexing) or (ContentDelivery and !Indexing)" />
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsyncSingleInstance" role:require="Standalone or (ContentManagement and Indexing) or (ContentDelivery and Indexing)" />
            </strategies>
            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>master</Database>
                <Root>/sitecore/content/tenant/stratum/home/products</Root>
              </crawler>
            </locations>
            <enableItemLanguageFallback>false</enableItemLanguageFallback>
            <enableFieldLanguageFallback>false</enableFieldLanguageFallback>
          </index>
        </indexes>
      </configuration>
    </contentSearch>
  </sitecore>
</configuration>

enter image description here

1 Answer 1

1

That's absolutely normal that Content is returned as null from Solr (as _content field) in SearchResultItem.

Why? With Solr you can configure if a field should be:

  • only indexed - it means that you can search in content of the field
  • or indexed and stored - you can search in content + you can retrieve the full value of the field.

If you open conf\managed-schema file in your index folder in Solr and search for _content, you will see:

<field name="_content" type="text_general" indexed="true" stored="false"/>

That stored="false" part tells Solr that it should not waste space on the drive and in memory for storing the original value of the field.

Still you can execute queries on the field - that part will work as expected.

2
  • When I change the value to true and populate schema in CMS, it's turning back to false. Also, please let me know the factors to consider to set it true, for a project.
    – sukesh
    Feb 13, 2023 at 11:33
  • 1
    You should not change it to true really. You should not use content of the Content field. It should be only used for searching in index, not for getting the content out of that field. If you need to get some values after you already got back search result item, check values of the fields which are used to generate Content field.
    – Marek Musielak
    Feb 13, 2023 at 12:06

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.