CDS: Search Annotations – Search.fuzzinessThreshold
Annotations enrich the CDS views but can be confusing as well. These series of blogs have my simplified explanation.
Search.fuzzinessThreshold annotation is used at the column level and it is used in along with Search.searchable ,Search.defaultSearchElement and Search.ranking to further define the search behavior in Fiori Element apps. The possible values are between 0 to 1 (in decimal upto 2 digits).
Syntax
Explanation
Fuzzy search is used nowadays everywhere so that even if user is making a mistake in typing, some relevant result is fetched. With the power of HANA + CDS, fuzzy search is now possible even with a large set of data. The value lies between 1 and 0, 1 (or 0.99) being fully strict search (ie search with the entered string only) and 0 likewise means no pattern at all. In fact, 0 in this case really means nothing and we should not go below 0.5 anyway. SAP recommends to use a value between 0.7 to 0.99. If search ranking has been specified that that column (close results) gets the preference.
Example: (Loading from Search.ranking)
@Search.searchable : true
....
define view ZCDS_EXAMPLE .....
.....
@Search.defaultSearchElement : true
@Search.ranking: #HIGH
@Search.fuzzinessThreshold : 0.9
key field1,
@Search.defaultSearchElement : true
@Search.randking: #LOW
field2,
field3,
......
In this example for field1, values matching 90% (or something similar) will also come up in the search result. Obviously the exact matches get the preference. If we reduce the value of the threshold then more distant records will be fetched. Try playing with this number to find your ideal match but I have seen 0.9 to 0.85 works really well.