Fuzzy Searching sypport in OUAF V22.214.171.124.0
By Acshorten-Oracle on Jun 17, 2013
One of the most common requirements in products using Oracle Utilities Application Framework is searching for records using various criteria. In Oracle Utilities Application Framework we provide a set of Query Zones that allow SQL to be used to retrieve information using whatever criteria is configured. In most cases we support precise and/or wildcarding (this is configurable). In Oracle Utilities Application Framework V126.96.36.199.0 we added support for inprecise or fuzzy searching using the facilities provided in Oracle Text.
Oracle Text is a component of all editions of the Oracle Database that allows for special indexes and additional clauses to provide a wide range of text searching and processing options. One of the major features of Oracle Text in Oracle Database 11gR2 is Name searching. This facility allows implementations to specify addtional SQL clauses to implement fuzzy or inprecise searching names and addresses in 20+ languages natively in the database.
For example, say you were looking for a customer with the name Bill. Fuzzy searching would allow Bill, William, Willy, Billy etc to be returned as well as they are valid variations of the name. This applies to surnames and addresses as well. For example, if you were looking at a surname of Smith, you could get results back of valid variations such as Smythe, or Smithe etc...
This Oracle Text facility is now interfaced using a new @fuzzy helper function (that is what I call it) to get the SQL query to implement the new SQL clauses easily in Query zones.
The process to implement this is summarized as follows:
- Enable Oracle Text on the database. By default, it is not enabled. This is a one off DBA DCL statement.
- Grant access to Oracle Text to the product users.This is a one off DBA DCL statement.
- Create Oracle Text indexes with the necessary parameters on the columns you want to apply the searching on. This will build special entries and variations for the SQL to use for you. The index creation allows you to customize the attributes and dictionaries used by the search to return the variations.
- Use the @fuzzy helper function in your Query zone SQL against the columns indexed and with the necessary configuration.
The @fuzzy helper function provides a number of parameters:
@fuzzy(term, score, numresults, weighting) where:
|term||Value to search on|
|score||The degress of fuzziness. Values between 1 - 80. The higher the number the more precise the search. Default is 60.|
|numresults||Number of variations to consider for the term. Number between 1 and 5000. Default is 100.|
|weighting||Whether the results are returned in order of score/weight. Specify WEIGHT to enable this.|
In the query zone you can default the values or provide them as parameters. For example:
To pass user data as term parameter and use default values of the remaining fuzzy operator parameters the zone SQL will need to be defined as following:
SELECT USER_ID, LAST_NAME from SC_USER WHERE CONTAINS(LAST_NAME, @fuzzy(:F1)) > 0;
To pass user data as term parameter in fuzzy operator, and to set score to 70, number results to 6, and to specify weight the zone SQL will need to be defined as following.
SELECT USER_ID, LAST_NAME from SC_USER WHERE CONTAINS(LAST_NAME, @fuzzy(:F1, 70, 6, ‘weight’)) > 0;
To pass user data as term parameter and a score in fuzzy operator, to set number results to 6, and to specify weight the zone SQL will need to be defined as following:
SELECT USER_ID, LAST_NAME from SC_USER WHERE CONTAINS(LAST_NAME, @fuzzy(:F1, :F2, 6, ‘weight’)) > 0;
Skip unnecessary parameters using the appropriate number of commas. For example:
SELECT USER_ID, LAST_NAME from SC_USER WHERE CONTAINS(LAST_NAME, @fuzzy(:F1,,,‘weight’)) > 0;
For more details of this facility and some general advice about Oracle Text refer to the Using Oracle Text for Fuzzy Searching Oracle Utilities Application Framework (Doc Id: 1561930.1) whitepaper available from My Oracle Support.
The key to the right results is the configuration of the Oracle Text Index. Refer to the Oracle Text documentation.