Enabling Text and Fuzzy Searches in SAP Fiori Apps

The descriptions in this topic refer to the range of functions for text and fuzzy searches that are provided in the context of SAP HANA.

Text and Fuzzy Searches

The full text searching (or just text search) provides you with the capability to identify naturallanguage terms that satisfy a query and, optionally, to sort them by relevance (ranking) to the query. The most common type of search is to find texts that contain the term specified and return them in the order of their similarity to these terms.

Fuzzy search is a fast and fault-tolerant search feature of SAP HANA. The basic concept behind the fault-tolerant search is that a database query returns records even if the search term (user input) contains additional or missing characters, or even spelling errors. Fuzzy search can be used in various applications -- for example, to trigger a fault-tolerant search in a structured database content, like a search for a product called 'coffe krisp biscuit' and you find 'Toffee Crisp Biscuits'.

Providing Freestyle Search Capabilities in SAP Fiori UI screen

Within the context of the ABAP programming model for SAP Fiori, you only need to enable the text and fuzzy search functionality in your data model definitions. For this purpose, you implement it in designated CDS views using appropriate text and fuzzy search annotations (listed below).

Annotations for Text- and Fuzzy Search

As the name suggests, search annotations enable the search feature on the CDS view elements.

First of all, you need the following CDS annotation at the view level:

Annotation and Value


@Search.searchable: true/false Defines whether a CDS view is generally relevant for search scenarios. This annotation provides a general switch and a means to quickly detect whether a view is search-relevant or not. Set to value true in order to enable search support by means of @Search annotations. Here, at least one view field must be defined as @defaultSearchElement at element level.

The annotations (required) at the element level are:

Annotation and Values


@Search.defaultSearchElement: true/false Specifies that the annotated element is to be considered in a full-text search
All view elements that are annotated for the default search define the search scope. (The search will be performed on all elements that have this annotation.).
@Search.fuzzinessThreshold: <value> This annotation specifies the least level of fuzziness the element has to have in order to be considered in a fuzzy search at all.

The <value> defines the threshold for a fuzzy search (how fuzzy scores are calculated when comparing two strings or two terms).

Possible values are: 0..1 The default value is 1. The fuzzy search algorithm calculates a fuzzy score for each string comparison. The higher the score, the more similar the strings are. A score of 1.0 means the strings are identical. A score of 0.0 means the strings have nothing in common.

@Search.ranking: <value> This annotation specifies how relevant the values of an element (view field) are for ranking, should the freestyle search terms match the element’s value.
The ranking can have the following values:
  • HIGH - The element is of high relevance; typically, this is useful for IDs and their descriptions.

  • MEDIUM - The element is of medium relevance; designated usually for important elements.

  • LOW - Although the element is relevant for a freestyle search, a hit for this element has no real significance for the ranking of a result item.


The listing below implements a search model for searching products. The model definition results from a join between two data sources that already specify the persistence layer for searching: both database tables are part of the EPM data model, where SMWD_PD provides product data and the table SMWD_TEXTS serves as the text reference table.

The annotation @Search.searchable: true marks the view as searchable. In addition, the elements Name and Category are annotated with @Search.defaultSearchElement: true. This means that a freestyle search is enabled on the search UI where it is possible to search for the annotated elements. The annotation @Search.fuzzinessThreshold: 0.7 (0.8) defines that the text search should be applied to the element Category with a similarity value of 70% and to the element Name with a similarity value of 80%.

  @Search.searchable : true 
  define view SearchForPuducts as select from snwd_pd as Product 
	left outer join snwd_texts as ProductDescription 
		on Product.desc_guid = ProductDescription.node_key 
	key Product.product_id as ID,
	@Search.defaultSearchElement : false 
	ProductDescription.language as Language,
	@Search.defaultSearchElement : true    
	@Search.fuzzinessThreshold : 0.8        
	@Search.ranking : #HIGH                 
	ProductDescription.text as Name,
	@Search.defaultSearchElement : true    
	@Search.fuzzinessThreshold : 0.7          
	@Search.ranking : #LOW             
	Product.category as Category


Standard filter allows to search for product category and product name
Figure 72: Standard filter allows to search for product category and product name