Generic search framework
Sitecore Experience Commerce (XC) release 10.0 introduces a generic, provider agnostic search framework that allows you to use the same search query syntax for search operations directed to any supported search provider. You can invoke search operations programmatically (using the Search plugin) or through an exposed API endpoint.
The generic search API provides capability for searching for catalog items, price cards, orders, customers, and promotions. The Commerce Engine also leverages the capability of the generic search framework in pipeline processes that require discovery of Commerce entities, such as price cards or promotions discovery, for example.
XC Business Tools search functionality does not make use of the generic search framework.
Search query models
The generic search framework defines the following models to support search queries:
-
SearchQuery
-
EqualsSearchNode
-
MatchAllSearchNode
-
FieldNameSearchNode
-
FieldValueSearchNode
Filter query models
The generic search framework defines the following models to support filter queries:
-
FilterQuery
-
MatchAllFilterNode
-
ContainsFilterNode
-
AndFilterNode
-
EqualsFilterNode
-
OrFilterNode
-
FieldNameFilterNode
-
FieldValueFilterNode
-
NotFilterNode
-
GreaterThanFilterNode
-
LessThanFilterNode
FilterNodeValueTypes
The FieldValueFilterNode parameter in a filter query takes a FilterNodeValueTypes value that supports the following data types:
-
Text : a string (default in most of the cases)
-
Integer number
-
Float number
-
Date : in format "yyyy-MM-ddTHH:mm:ss.FFFZ"
-
Boolean ("true" or "false")
-
String in collection : the text inside the collection. For example: associated catalogs in Promotions index.
Generic search API endpoint
The generic search framework exposes the following GenericSearch API end-point {{ServiceHost}}/{{ShopsApi}}/GenericSearch().
You can use the GenericSearch sample request in Postman to exercise the API.
The GenericSearchCommand command
The generic search framework defines the GenericSearchCommand command. The GenericSearchCommand command calls the IGenericSearchPipeline pipeline.
GenericSearchCommand parameters
The following table lists the parameters of a GenericSearchCommand operation:
|
Parameter |
Description |
|---|---|
|
|
The name of a |
|
|
The query that consists of search criteria. The parsed version is passed as a search query to the search provider. |
|
|
The query that consists of filter criteria. The parsed version is passed as a filter query to the search provider. |
|
|
The options associated with the search operation:
|
Search and filter nodes
The generic search framework defines search nodes and filter nodes. A search node represents the primary match criteria in a search query. A filter node represents the match criteria in a filter query. You use a filter query to further refine a search and limit the number of returned results.
Search nodes
The following table lists and describes search nodes used in a search query:
|
Search node |
Description |
|---|---|
|
|
Matches all documents in the index. |
|
|
Uses a specified |
Filter nodes
The following table lists and describes filter node operators that you can use in a filter query to further refine search results and hone in on specific content:
|
Filter node |
Description |
|---|---|
|
|
Matches all documents in the index. This is the equivalent of a search that does not use a filter. |
|
|
Matches only documents that contain a substring specified in the Note In Azure Search, the |
|
|
Uses the specified |
|
|
Allows to build complex queries, in conjunction with other nodes. Represents a logical AND operation to build complex queries such as: |
|
|
Allows to build more complex queries by combining two clauses with OR relationship. The results returns documents if any of the clauses is true. |
|
|
Allows to invert the logic of some nodes. |
|
|
In conjunction with |
|
|
In conjunction with |
Examples of search and filter queries
The following provides some examples of search and filter queries using C# programming language.
Example of a search query using the MatchAllSearchNode criteria
MatchAllSearchNode criteriaThe following sample shows an example of a query that uses the MatchAllSearchNode criteria:
var sq = new SearchQuery(); -
search query to match all documents. The same as:
var sq = new SearchQuery(new MatchAllSearchNode())
Example of a search query using the EqualsSearchNode criteria
EqualsSearchNode criteriaThe following sample shows an example of a query that uses the EqualsSearchNode criteria:
var sq = new SearchQuery(
new EqualsSearchNode(
new FieldNameSearchNode("fieldName"),
new FieldValueSearchNode("fieldValue"))); Example of a filter query using the MatchAllFilterNode criteria
MatchAllFilterNode criteriaThe following sample shows an example of a query that uses the MatchAllFilterNode criteria:
var fq = new FilterQuery() -
applies no filtering on search results. The same as
var fq = new FilterQuery(new MatchAllFilterNode())
Example of a filter query using the GreaterThanFilterNode criteria
GreaterThanFilterNode criteriaThe following sample shows an example of a complex query that uses the GreaterThanFilterNode criteria:
var fq = new FilterQuery(
new AndFilterNode(
new ContainsFilterNode(
new FieldNameFilterNode("fieldName"),
new FieldValueFilterNode("fieldValue")),
new GreaterThanFilterNode(
new FieldNameFilterNode("dateFieldName"),
new FieldValueFilterNode("dateValue", FilterNodeValueType.Date)))); - filter query to return only those documents that contain text "fieldValue" within "fieldName" field and "dateFieldName" is greater than "dateValue".
The "dateValue" must be stated in this format: "yyyy-MM-ddTHH:mm:ss.FFFZ", for example: "2000-01-01T12:00:00.000Z" where:
-
yyyyis the year. -
MMis the month. -
ddis the day of the month. -
Tis the time delimiter. -
HHis the time in hours. -
mmrepresents minutes. -
ssrepresents seconds. -
FFFrepresents fractions of a second (without zeroes). -
Zis a time zone designator for the zero UTC offset.
Example of a complex filter query
The following sample shows an example of a complex filter query:
var fq = new FilterQuery(
new OrFilterNode(
new EqualsFilterNode(
new FieldNameFilterNode("fieldName"),
new FieldValueFilterNode("booleanValue", FilterNodeValueType.Boolean)),
new NotFilterNode(
new EqualsFilterNode(
new FieldNameFilterNode("floatFieldName"),
new FieldValueFilterNode("1.0",FilterNodeValueType.FloatNumber))))); -
filter query to return only those documents where "fieldName" equals
Boolean value "booleanValue" or "floatFieldName" not equals
1.0 float number.