@cds.search
annotationString
are searchable by default.@CDS.search
AnnotationString
are searchable by default unless you decide to override this default. The reasoning behind this design decision is that most of the time, you’re searching for elements typed as String
rather than for elements typed as UUID
, Date
, Time
, DateTime
, or Timestamp
.@CDS.search
annotation looks as follows:@cds.search: {
element1,
element2: true,
element3: false,
element4.elementA
}
entity MyEntity ...
element1
, ..., element4
are the element names of an annotated entity. To exclude an element from the search, annotate it with false
.String
) searchable via the $search
query option, the element's entity must be explicitly annotated with the @CDS.search
annotation, for example:ID
and title
:@cds.search: { ID, title }
entity Books {
key ID: UUID;
title: String;
}
String
, title
, descr
, and isbn
— default, no annotation required:
entity Books {
key ID: UUID;
title: String;
descr: String;
isbn: String;
author: Association to Authors;
}
title
:
@cds.search: { title }
entity Books { ... }
@cds.search: { title: true }
entity Books { ... }
title
and descr
:
@cds.search: { title, descr }
entity Books {
key ID: UUID;
title: String;
descr: String;
isbn: String;
author: Association to Authors;
}
title
, descr
, and isbn
:
@cds.search: { title, descr, isbn }
entity Books {
key ID: UUID;
title: String;
descr: String;
isbn: String;
author: Association to Authors;
}
String
excluding the element isbn
(search by title
and descr
😞
@cds.search: { isbn: false }
entity Books {
key ID: UUID;
title: String;
descr: String;
isbn: String;
author: Association to Authors;
}
ID
and title
:
@cds.search: {
ID: true,
title: true,
descr: false // superfluo (just for demostration purposes)
}
entity Books {
key ID: UUID;
title: String;
descr: String;
isbn: String;
author: Association to Authors;
}
@Search.defaultSearchElement
is deprecated and will be removed in future versions. In the meantime, @CDS.search
supersedes @Search.defaultSearchElement
. That is, if both annotations are defined, @CDS.search
wins.
The metadata information that defines which elements are searchable is based on Core Data Services. We use the SAP Cloud Application Programming Model compact representation of data models known as Core Schema Notation to determine which elements are searchable for an entity at runtime.
Based on the premise that Core Schema Notation is a compact static data structure representation of CDS models. We implemented a caching mechanism that lazily computes the searchable elements and caches the result so that future search requests for that entity data are served up faster.
$search
system query option to decouple database-specific processing from the OData service layer, thus resulting in better performance when forwarding search requests to external services and fewer runtime exceptions.sap-language
| x-sap-request-language
URL’s parameters. Once the Node.js Runtime by content negotiation selects a user locale proposal, it uses the corresponding ahead-of-time compiled localized view with the user locale to resolve the localized texts.service BookshopService {
// search by title (default)
@cds.search: { title }
entity Books {
key ID : UUID;
title : localized String;
}
}
BookshopService
service definition to SQL format, the BookshopService_Books
, BookshopService_Books_texts
database tables are generated.BookshopService_Books_texts
table doesn’t have a counterpart in the service definition. By convention, when an entity contains localized elements, the compiler generates an additional table with the same name suffixed with _texts
, including the following columns:ID
columnlocale
columnBooks
in this case)localized_BookshopService_Books
view is generated in SQL DDL to read localized data with fallback easily.╰─$ cds compile srv/books.cds --to hdbtable
COLUMN TABLE BookshopService_Books (
ID NVARCHAR(36) NOT NULL,
title NVARCHAR(5000),
PRIMARY KEY(ID)
) WITH ASSOCIATIONS (
MANY TO MANY JOIN BookshopService_Books_texts AS texts ON (texts.ID = ID),
MANY TO ONE JOIN BookshopService_Books_texts AS localized ON (localized.ID = ID
AND localized.locale = SESSION_CONTEXT('LOCALE'))
)
COLUMN TABLE BookshopService_Books_texts (
locale NVARCHAR(14) NOT NULL,
ID NVARCHAR(36) NOT NULL,
title NVARCHAR(5000),
PRIMARY KEY(locale, ID)
)
VIEW localized_BookshopService_Books AS SELECT
L_0.ID,
coalesce(localized_1.title, L_0.title) AS title
FROM (
BookshopService_Books AS L_0
LEFT JOIN BookshopService_Books_texts AS localized_1
ON localized_1.ID = L_0.ID
AND localized_1.locale = SESSION_CONTEXT('LOCALE')
)
WITH ASSOCIATIONS (
MANY TO MANY JOIN BookshopService_Books_texts AS texts ON (texts.ID = ID),
MANY TO ONE JOIN BookshopService_Books_texts AS localized ON (localized.ID = ID
AND localized.locale = SESSION_CONTEXT('LOCALE'))
)
coalesce
function to filter the localized title
field.coalesce
function prevents push-down of filter operations to the SAP HANA database column store layer. As a result, search queries over large data sets show suboptimal performance and might lead to out-of-memory issues in some high-load scenarios.cds.env.features.optimized_search
to true
.localized
association in schema notation format to generate SQL statements that resolve the localized data in a way that is optimized for the underlying database. This is, however, only possible if the localized
association is present, with is always the case when at least one localized element is defined in the target entity.Books
model to schema notation:╰─$ cds compile srv/books.cds
{
"definitions": {
"BookshopService": {
"kind": "service"
},
"BookshopService.Books": {
"kind": "entity",
"@cds.search.title": true,
"elements": {
"ID": {
"key": true,
"type": "cds.UUID"
},
"title": {
"localized": true,
"type": "cds.String"
},
"texts": { // points to all translated texts for the given entity
"type": "cds.Composition",
"cardinality": {
"max": "*"
},
"target": "BookshopService.Books.texts",
"on": [
{
"ref": [
"texts",
"ID"
]
},
"=",
{
"ref": [
"ID"
]
}
]
},
"localized": { // association points to the translated texts and is narrowed to the request’s locale
"type": "cds.Association",
"target": "BookshopService.Books.texts",
"on": [
{
"ref": [
"localized",
"ID"
]
},
"=",
{
"ref": [
"ID"
]
},
"and",
{
"ref": [
"localized",
"locale"
]
},
"=",
{
"ref": [
"$user",
"locale"
]
}
]
}
}
},
"BookshopService.Books.texts": {
"kind": "entity",
"@odata.draft.enabled": false,
"elements": {
"locale": {
"key": true,
"type": "cds.String",
"length": 14
},
"ID": {
"@odata.containment.ignore": true,
"key": true,
"type": "cds.UUID"
},
"title": {
"localized": false,
"type": "cds.String"
}
}
}
},
"meta": {
"creator": "CDS Compiler v2.2.0",
"flavor": "inferred"
},
"$version": "2.0"
}
localized
association points to the translated texts and is additionally narrowed to the request’s locale. In addition, the texts
composition points to all translated texts for the Books
entity.BookshopService_Books
and BookshopService_Books_texts
database tables at runtime, avoiding the performance overhead of the coalesce
function when filtering localized data.CONTAINS
PredicateLIKE
predicate, you can use the CONTAINS
predicate in the WHERE
clause of a SELECT
statement to search for one or multiple columns tables.CONTAINS
predicate looks as follows:CONTAINS (<contains_columns>, <search_string> [, <search_specifier>])
SELECT * FROM <table_name>
WHERE CONTAINS ((<column1>, <column2>, <column3>), <search_string>)
LIKE
clause might cause a high CPU load on SAP HANA servers in some scenarios because the database optimizer can’t push down the LIKE
expression to the column storage layer.CONTAINS
.$search
implementation on CONTAINS
. Unfortunately, search queries based on CONTAINS
aren’t strictly comparable to those based on LIKE
(see CONTAINS
limitations). So, we implemented a branch prediction algorithm to determine whether to use CONTAINS
at runtime for search queries instead of LIKE
.cds.env.features.optimized_search
to true
.cds.env.features.optimized_search
to true
) and provided support for the @cds.search
entity-level annotation.You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
40 | |
25 | |
17 | |
13 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 |