Tie Breaking

Custom tie breaking rules allow you to control how records are ordered in the event that multiple records receive the same score. Tie breaks are specified by attaching an LPAR_LST_TIEBREAKS list lpar to the search parameters list. This is an ordered list of tie breaking rules. The first rule in the list is used as the primary tie breaking rule. If this rule also results in a tie, the next rule is used. If all tie breaking rules are exhausted, the resulting ordering is not defined. The tie breaking rules available are:

LKT_TIEBREAK_FIELDVAL

Records are ordered based on the comparison of the value of a field in the records. The field to compare is specified by adding an LPAR_INT_TIEBREAKPARAM to the LPAR_LST_TIEBREAK list with the value being the field number. Text fields are ordered lowest first (that is alphabetically), other fields are ordered greatest first.

LKT_TIEBREAK_ALIGNMENT

Records where most of the matching text occurs near the front of the record are ordered before records where most of the matching text occurs near the end of the record. As alignment is only meaningful for cognate and simple queries this tie breaking rule is ignored if query expressions are used.

LKT_TIEBREAK_RECID

Records are ordered in sorted order by their record key. The ordering is based on the raw code values of the bytes and does not take into consideration any locale ordering rules for characters. As record keys must be unique this is guaranteed to break a tie and produce a fixed, stable, ordering for the records.

LKT_TIEBREAK_RECLEN

This is deprecated. This is equivalent to LKT_TIEBREAK_SCORETYPE with a score type of symmetric.

LKT_TIEBREAK_SCORETYPE

Records are ordered first by the primary sort score and then ties are broken based on a secondary score type. For instance, you can sort primarily by normal score and then tie break by symmetric score. The score type is specified by adding an LPAR_INT_TIEBREAKPARAM to the LPAR_LST_TIEBREAK list with a value of: LKT_SCORE_NORMAL, LKT_SCORE_REVERSE, LKT_SCORE_SYMMETRIC, LKT_SCORE_MIN, LKT_SCORE_MAX or LKT_SCORE_IT.

Each tie break is specified by adding an LPAR_INT_TIEBREAK or LPAR_LST_TIEBREAK to the tie break list.

The following sample code creates a tie breaking rule set which orders records first by symmetric score, then by record key. This is in fact the default tie breaking rule used if no tie breaking rule is specified.

 

lpar_t tiebreaks;
lpar_t tb;
tiebreaks = lpar_create_lst(LPAR_LST_TIEBREAKS);
tb = lpar_create_lst(LPAR_LST_TIEBREAK);
lpar_append_lst(tb, lpar_create_int(LPAR_INT_TIEBREAK,LKT_TIEBREAK_SCORETYPE));
lpar_append_lst(tb, lpar_create_int(LPAR_INT_TIEBREAKPARAM,LKT_SCORE_SYMMETRIC));
lpar_append_lst(tiebreaks, tb);
tb = lpar_create_int(LPAR_INT_TIEBREAK,LKT_TIEBREAK_RECID);
lpar_append_lst(tiebreaks,tb);

 

The lpar tie breaks can be appended to the search parameter list to use these tie breaking rules in a search.