Search client
The Search client in the Web SDK enables developers to perform powerful and flexible search operations on entities. It supports full-text search, filtering, sorting, pagination, and localization.
The following methods are available.
SearchAsync
Performs a search for entities using a SearchRequest object that supports a wide range of filtering, sorting, and configuration options.
The parameters you can use with the SearchAsync method are detailed in the following table.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
The search query string. |
|
|
string |
Template for logical grouping. |
|
|
string |
Default search configuration. |
|
|
string |
Configuration category. |
|
|
long |
Component ID. |
|
|
CultureInfo |
Culture info (defaults to |
|
|
SortingRequestResource |
Sorting expression. |
|
|
IDictionary<string, int> |
Custom sorting. |
|
|
int |
Records to skip (pagination). |
|
|
int |
Records to take (pagination, default is 25). |
|
|
List |
Filters to apply. |
|
|
List |
Full-text filters. |
|
|
List |
Fields to include in results. |
|
|
long |
Saved selection ID. |
|
|
string |
View type for results. |
|
|
DateTime |
Calendar filter start date. |
|
|
DateTime |
Calendar filter stop date. |
|
|
SelectionPoolFilterResource |
Selection pool filter. |
|
|
List |
Aggregation requests. |
|
|
IEnumerable |
Nested relations to include. |
|
|
SearchGroupRequestResource |
Grouping request. |
|
|
bool |
Indicates if this is the initial request. |
|
|
bool |
Use user settings. |
|
|
bool |
Use localization. |
|
|
VisualSearchRequestResource |
Visual search request. |
|
|
IDictionary |
Additional extension data. |
The following code provides a full-text search example.
var searchRequest = new SearchRequest
{
ComponentId = 840,
Culture = new CultureInfo("en-US"),
Sorting = new SortingRequestResource
{
FieldName = "createdon",
Ascending = false
},
Skip = 0,
Take = 10,
FullTextFilters = new List<string> { "Keyword" },
Fields = new List<string> { "Title", "Description" }
};
var result = await MClient.Search.SearchAsync(searchRequest);
GetAllFacetValuesAsync
Retrieves all available values for a specified facet field using an AllFacetsRequest.
The parameters you can use with the GetAllFacetValuesAsync method are detailed in the following table.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Name of the facet field. |
|
|
string |
Optional query for facet values. |
|
|
string |
Name of the search configuration. |
|
|
CultureInfo |
Culture for facet values. |
|
|
long |
Component ID. |
|
|
IList |
Filters to apply. |
|
|
bool |
Use user settings. |
|
|
bool |
Use localization. |
|
|
int |
Records to skip (pagination). |
|
|
int |
Records to take (pagination). |
The following code provides an example of how to get facet values.
var allFacetsRequest = new AllFacetsRequest
{
FacetFieldName = $"taxonomy_items.{tagId}.children",
Query = "",
SearchConfigurationName = "DefaultSearchConfig",
Culture = new CultureInfo("en-US"),
ComponentId = 840,
Filters = new List<FieldFilterRequestResource>(),
TakeUserSettings = false,
L10N = false,
Skip = 0,
Take = 10
};
var result = await MClient.Search.GetAllFacetValuesAsync(allFacetsRequest);Exceptions
-
ArgumentNullException– if the request is null. -
ArgumentOutOfRangeException– ifTakeorSkipis negative. -
ArgumentException– if any filter or culture is invalid.