The following IDX Definition disables Full-Key-Data (which stores all IDT columns in the IDX) and specifies a list of IDT columns to be appended after the 8-byte fuzzy key (Name and State). Up to 5 columns (or part thereof) may be specified with the Key-Data parameter, as long as the total key length does not exceed the maximum key size permitted by the particular DBMS (~ 250 bytes).
idx-definition
*==================
NAME= namev2
ID= u5
IDT-NAME= IDT305
KEY-LOGIC= SSA, System(default), Population(test),
Controls ("FIELD=Person_Name KEY_LEVEL=Standard"),
Field("name")
KEY-DATA= Name,State
OPTIONS= --Full-Key-Data
The full syntax for specifying Key-Data is:
KEY-DATA = field[,length,offset], ...
where
field
is the field name,
length
is an optional number of bytes to include (the entire field is included by default), and
offset
is an optional starting offset (base 0).
The Search-Definition includes a filter clause that calls a user-written function. The function call must include a field named
SSAKEY
to provide the function with access to the Key-Data. The response code returned by the function determines whether the row is kept or discarded. For example:
search-definition
*====================
NAME= search-filter-ny
IDX= namev2
KEY-LOGIC= SSA, System(default), Population(test),
Controls ("FIELD=Person_Name SEARCH_LEVEL=typical"),
Field("name")
KEY-SCORE-LOGIC= SSA, System(default), Population(test),
Controls("PURPOSE=Person_Name MATCH_LEVEL=Typical"),
Matching-Fields("Name:person_name")
FILTER= "#ids_sql_filter.demo(SSAKEY)=1"
OPTIONS= Filter-Replace
Note that the filter statement:
begins with ’#’. This character informs the search engine to use the new semantics, otherwisethe original filter mechanism is used.
passes the entire IDX record (
SSAKEY
) to the function named
ids_sql_filter.demo
. The function examines the Key-Data and returns a decision to either keep or discard the row. The response-code is arbitrary. In this example, a value of 1 will keep the candidate row.
The corresponding function, written in PL/SQL, is as follows.
CREATE OR REPLACE PACKAGE BODY ids_sql_filter AS
FUNCTION demo (
ssakey IN RAW)
RETURN NUMBER
IS
rec VARCHAR (255);
state VARCHAR (2);
BEGIN
rec := utl_raw.cast_to_varchar2 (ssakey);
state := SUBSTR(rec,33,2);
IF (state = ’NY’) THEN
RETURN 1;
END IF;
RETURN 0;
END demo;
END ids_sql_filter;
The sample function performs the following actions:
converts the input parameter
ssakey
from raw to char, which allows the Key-Data to be extracted using a substring function.
extracts the value of State from the Key-Data. In this case, the Key-Data contains an 8-byte fuzzy-key, followed by a Name (for a length of 24 bytes), followed by State (2 bytes). Thus, the State field begins at offset 32 (base 0). The Oracle substring function assumes offsets start from 1. Therefore the substring command refers to position 33 for a length of 2 bytes to exact the value of State.
The extracted State value is compared to a value of ’NY’. When the candidate value is identical, the function returns 1, meaning that the candidate row should be kept. Otherwise, it returns 0, which effectively discards the candidate row.
Note that the value of
NY
does not need to be hard-coded. It could have been passed in as the second parameter to the function by hardcoding it in the filter statement, or even set dynamically by using a substitution variable. For example,
FILTER= "#ids_sql_filter.demo(SSAKEY,$1)=1"
When using this alternative SQL Filter method, only the Key-Data fields will be available for matching, display, and return as part of the search results.