Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
patil477pavan
Explorer
Introduction:

What is Fuzzy Search ? 

  • A technique of finding the strings that match a pattern approximately (rather than exactly).

  • A fault-tolerant search, which returns records even if the search term contains typos or additional/missing characters.

  • Example: Typing ‘Wether’ in Google will also return a list of hits corresponding to ‘Weather/Whether’.

  • The below figure gives us the clear idea.



Fig: Google (Source)


Fuzzy Search in SAP HANA:

  • Can be applied in the WHERE clause of a SELECT statement using the function ‘CONTAINS’ with the option ‘FUZZY’

  • SELECT * FROM <table_name> WHERE CONTAINS (<column_name>, <search_string>, FUZZY(x) ).

  • <table_name> can be name of a column table, attribute view or a SQL view created with the CREATE VIEW statement

  • FUZZY(x) specifies the degree of accuracy required between the strings used in comparison (<column_name> and <search_string>)

  • ‘x’ in FUZZY(x) is called a fuzzy factor and can have values between 0 and 1.


Key Points:

  • If only FUZZY is specified, it takes the value of x as 0.8

  • If FUZZY(x)/FUZZY is not provided, an exact match is searched.

  • CONTAINS function can also be used in a SELECT query with JOIN.

  • 0 being least accuracy and 1 being highest accuracy.


What is AMDP Class ? 

  • An AMDP Class is a global class existing in the class library with a tag interface IF_AMDP_MARKER_HDB (to indicate AMDP classes for the HANA Database Server)

  • Can contain both regular methods and AMDP methods

  • A method is indicated as an AMDP method in the implementation section of the class using the addition BY DATABASE PROCEDURE in the METHOD statement

  • Can only be created using ADT.

  • An AMDP method is called in an ABAP program in the same way as any other ABAP Objects method.


How to implement Fuzzy Search using AMDP Class ? 

Custom Table (ZSCARR) created as a part of this blog post and maintained the entries as shown in the below figures.



Simple Use Case:

Suppose , you have 100000's of record and you need to join multiple tables and fetch the output/data accordingly and the end user just wants to see the probable output based on the input provided by him. In this case , Fuzzy Search Technique comes handy.

  • AMDP Class with Fuzzy Technique:



Fuzzy Search AMDP Class




  • Consuming AMDP Class in Report Program:



Fuzzy Search Report Program


Selection Screen:




  • Output when Fuzzy is  0.1





  • Output when Fuzzy is  0.5





  • Output when Fuzzy is  1



Summary:

  • Fuzzy Search is a technique of finding strings that match a pattern approximately (rather than exactly).

  • Fuzzy Search in SAP HANA makes use of two functions – CONTAINS() which performs search on strings and SCORE() which returns fuzzy score.

9 Comments
Labels in this area