Perform search in an index

The following search example demonstrates how to perform search in an index.


The recommended way to perform search when using the API is to resolve an instance of the ISearchResultsBuilder interface by invoking ObjectFactory.Resolve<ISearchResultsBuilder>().
The resolved object will be used to call the method IEnumerable<IDocument> Search(SearchBuilderParams searchParams, out int hitCount), which will take care to create the search query and invoke the configured search service. The Search method returns all the search results that are found as IEnumerable<IDocument>, takes a set of parameters organized in SearchBuilderParams object, and outputs hitCount (the number of the returned search results).

The SearchBuilderParams object must include the IndexName and SearchText properties.
You can also use this object to set optional properties: SearchFields, Culture, HighlightedFields, OrderBy, Skip, Take, ScoringSettings, GetResultsFromAllSites, SearchFilter.

  • If Culture property is not provided, it will be taken from the current context.
  • The ScoringSettings property can only be used with Azure Cognitive Search service, when scoring profiles are configured for the search index.
  • When a search index is made common for several sites or for all sites in your Sitefinity CMS, GetResultsFromAllSites can be set to retrieve results only for the current site.
  • The SearchFilter property represents additional filters that can be added and applied to the search query. This can be done by resolving an instance of ISearchFilter interface and setting one or more SearchFilterClause to the object.Clauses field. Each filter created this way can be added to the group filters collection of another ISearchFilter instance, giving the possibility to use nested filters with different operators applied.


 

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?