Sitecore Search and Custom Entity

Sitecore Search and Custom Entity

In this article, I will review how to create a custom entity in Sitecore Search and explore the various possibilities available for this purpose.

To create a custom entity, first navigate to the Administration section in the Sitecore Search menu. Then, open Domain Settings. Within the General Settings section, you will find an Entities part.

 

 

 

In the Entities section, you will see an Edit button. Click this button to open a popup window, where you will have the options to create new entities and edit existing ones. There will already be a Content entity, which is the default entity.

 

 

To create a new entity, click Add Entity. Sitecore Search will suggest three options: Category, Store, and Custom Entity. Each of these options will follow a specific Attribute Template: Category uses the Base Attributes Template for Category, while Store and Custom Entity use the Base Attributes Template.

If you choose Category or Store, note that you cannot update the name for these entities and you can only create each of these entities once. Therefore, I recommend choosing Custom Entity, where you have full control over all settings.

Consider the available base templates: Base Attributes Template, Base Attributes Template for Product, Base Attributes Template for Category, Attributes Template for Content, Base Spec for Order Cloud 2, Order Cloud Product Spec 2, Attributes Template for Product - Generic Industry, Base Empty Spec, Store, and Fitment. Each template has its own set of attributes. In this article, I will not review all templates; however, for the purpose of this article, I will focus on the Base Attributes Template. I will create News entity.

 


 

After saving a new entity, you will see blue dots, indicating that your changes have been saved but not yet published. To apply these changes, you need to click the Publish button. But I will not to do this now, because I will review how to create a new attribute for our entity.

 


 

If you open the Attributes section, you will see all attributes for both the Content entity and the News entity that was created earlier. Through filtering, you can display only the attributes for a specific entity.

 



 

As you can see, there are duplicate attributes, such as Id, Source, Stats, and Document Activeness. Sitecore Search does not provide the capability to reuse existing attributes; each attribute must be created specifically for a particular entity.

Now, let's create a new attribute called Main Text for our News entity. To do this, click the Add Attribute button, which will open a popup window for creating a new attribute.

 

 

Let's review the Settings section of the popup, which contains the following fields:

  1. Entity: Specifies the entity for which the attribute is being created.
  2. Display Name: The human-readable name of the attribute.
  3. Attribute Name: The internal name used to reference the attribute.
  4. Placement: Defines where the attribute appears within the entity.
  5. Data Type: Specifies the type of data the attribute will store.
  6. Default Value: Optional field to set a default value for the attribute.
  7. Description: Provides a brief description or explanation of the attribute.
  8. Alias: Other names that this attribute may be referred by for backwards compatibility.
  9. Alias in Request URL: List of alias names that this attribute may be referred to in the URL query parameters.
  10. Icon: Optional field for assigning an icon to the attribute.
  11. Mark as: Allows marking the attribute as required, sitecore computed, sitecore learned.
  12. Properties: Additional properties or settings related to the attribute.

These fields allow for detailed customization and configuration of the new attribute within the Sitecore Search system. The required fields for creating an entity are Entity, Display Name, Attribute Name, Placement, Data Type. Attributes in Sitecore Search can have the following data types:

  1. Integer
  2. Double
  3. Array of Integer
  4. Float
  5. Array of Float
  6. Boolean
  7. String
  8. Array of Strings
  9. GEO (Geographical Coordinates)
  10. Object
  11. Array of Objects
  12. Timestamp

As you can see, Sitecore Search offers a wide range of data types to cover various requirements you may have when defining attributes for entities.

Also pay attention to the Properties field, because if you want to get a new field to response, need to check Return In Api Response. 

 


 

Now let's take a look at the Use For Feature section. Here we have the following checkboxes: Facet, Filter, Personalization, Search Ranking, Sorting Options, Textual Relevance, Suggestions Blocks. I think you have realized that if you select any checkbox, a new field will be added to the next feature.

 


 

After saving, you will see the new attribute listed in the table, alongside other attributes. This allows you to easily track and manage all attributes associated with the entity within Sitecore Search.

 


 

Now that we've covered creating custom entities and attributes, it's important to address Feature Configuration, which plays a vital role in tailoring our search functionality. We have several key features available, including Api Responsiveness, Facets, Filters, Personalization, Sorting Options, Suggestions Blocks, and Textual Relevance. While I won't delve into this aspect of customization in this article, it's a topic I plan to explore in the future as my understanding of these features grows. Stay tuned for more insights into optimizing search functionality in Sitecore.

 


 

Having explored the process of creating custom entities and attributes, as well as the fundamental features of configuration, one can understand how to effectively customize search functionality within the Sitecore system. Working with Sitecore Search offers a wide range of possibilities for crafting and configuring one's own data structure, allowing for search adaptation to specific project requirements. In this article, we covered the essential steps for creating custom entities and attributes, while also discussing the importance of feature configuration for optimizing search functionality. Although certain aspects, such as feature customization, were left beyond the scope of this article, they represent an important area for further exploration. With deepened knowledge and experience in working with Sitecore, one can achieve maximal search efficiency and develop custom solutions that best suit the project's needs.