Querylet References

In some complex query situations, the identical querylet must be repeated two or more times at different locations in the query tree. The example in the Match Case score combiner section shows one of these queries. In this example the querylets for each category are repeated twice, one time for each match rule. Some situations might require far more match rules. Because the category querylets are repeated for each match rule, this can result in many copies of each category querylet appearing in the query tree, and the querylet being reevaluated many times. This incurs a substantial performance penalty. The result is the same every time it is evaluated, so it is not necessary to reevaluate each category querylet each time it appears. Instead a querylet reference can be used.

A querylet reference can be used anyplace an LPAR_LST_QEXPR can be used. The result output by a querylet reference is the same as the result of the querylet it references. No reevaluation is performed; it uses the same output.

A querylet reference is specified as an LPAR_LST_REFQUERY. This list contains exactly one item: LPAR_STR_QLETNAME. The name in this item must match a named querylet on the query tree (see First Valid Score Combiner for more information on this). There is no order dependency between the reference and the referenced querylet. The referenced querylet only needs to be somewhere on the query tree. If there is no querylet with the given name on the query tree, a DVK_ERR_QLETREFBROKEN error is returned.

A querylet reference can reference any named querylet. This can be a leaf, or a query combiner with a complex sub-tree beneath it.

A querylet reference cannot be named. References to references are not allowed.

Circular references are not allowed. A querylet reference is not allowed to reference a querylet that has a node on its sub-tree that is a reference to an ancestor of the querylet reference. If a circular reference is detected, a DVK_ERR_QLETREFLOOP error is returned.

The following example shows how the MatchCase example can be modified to use querylet references. New or changed lines are in bold face font.

 

/* Querylet LPARs for each category (setting not shown) */
lpar_t name_cat_qry ; /* name category querylet */
lpar_t street_cat_qry ; /* street address category querylet */
lpar_t location_cat_qry ; /* location category querylet */
lpar_t phone_cat_qry ; /* phone number category querylet */
lpar_t dob_cat_qry ; /* date of birth category querylet */
/* References to the category queries */
lpar_t name_ref ;
lpar_t street_ref ;
lpar_t location_ref ;
lpar_t phone_ref ;
lpar_t dob_ref ;
/* Our Intermediate Querylets */
lpar_t cat_qrys ; /* category queries for match rules */
lpar_t cat_ref_qrys ; /* category queries as references */
lpar_t rule_1_qry ; /* Match Case query for rule 1 */
lpar_t rule_1_qopts ; /* Match Case settings for rule 1 */
lpar_t rule_2_qry ; /* Match Case query for rule 2 */
lpar_t rule_2_qopts ; /* Match Case settings for rule 2 */
lpar_t final_query_args ; /* arguments for full query */
/* The final query. */
lpar_t final_query ;
/* For example we define rule parameters as static values */
/* These could be read in from a configuration file. */
/* Rule 1 */
/* ------ */
/* ... as before ... */
/* Rule 2 */
/* ------ */
/* ... as before ... */
/* We must name the category queries to reference them. */
lpar_append_lst(name_cat_qry,
lpar_create_str(LPAR_STR_QLETNAME, "Name Cat")) ;
lpar_append_lst(street_cat_qry,
lpar_create_str(LPAR_STR_QLETNAME, "Street Cat")) ;
lpar_append_lst(location_cat_qry,
lpar_create_str(LPAR_STR_QLETNAME, "Location Cat")) ;
lpar_append_lst(phone_cat_qry,
lpar_create_str(LPAR_STR_QLETNAME, "Phone Cat")) ;
lpar_append_lst(dob_cat_qry,
lpar_create_str(LPAR_STR_QLETNAME, "DOB Cat")) ;
/* Create the query expression arguments list. */
cat_qrys = lpar_create_lst(LPAR_LST_QEXPR_ARGS) ;
lpar_append_lst(cat_qrys, name_cat_qry) ;
lpar_append_lst(cat_qrys, street_cat_qry) ;
lpar_append_lst(cat_qrys, location_cat_qry) ;
lpar_append_lst(cat_qrys, phone_cat_qry) ;
lpar_append_lst(cat_qrys, dob_cat_qry) ;
/* Create Reference Querylets to the category querylets. */
name_ref = lpar_create_lst(LPAR_LST_REFQUERY);
lpar_append_lst(name_ref,
lpar_create_str(LPAR_STR_QLETNAME, "Name Cat")) ;
street_ref = lpar_create_lst(LPAR_LST_REFQUERY);
lpar_append_lst(street_ref,
lpar_create_str(LPAR_STR_QLETNAME, "Street Cat")) ;
location_ref = lpar_create_lst(LPAR_LST_REFQUERY);
lpar_append_lst(location_ref,
lpar_create_str(LPAR_STR_QLETNAME, "Location Cat")) ;
phone_ref = lpar_create_lst(LPAR_LST_REFQUERY);
lpar_append_lst(phone_ref,
lpar_create_str(LPAR_STR_QLETNAME, "Phone Cat")) ;
dob_ref = lpar_create_lst(LPAR_LST_REFQUERY);
lpar_append_lst(dob_ref,
lpar_create_str(LPAR_STR_QLETNAME, "DOB Cat")) ;
/* And a query expression argument list using references. */
cat_ref_qrys = lpar_create_lst(LPAR_LST_QEXPR_ARGS) ;
lpar_append_lst(cat_qrys, name_ref) ;
lpar_append_lst(cat_qrys, street_ref) ;
lpar_append_lst(cat_qrys, location_ref) ;
lpar_append_lst(cat_qrys, phone_ref) ;
lpar_append_lst(cat_qrys, dob_ref) ;
/* Define Rule 1 Query */
/* ------------------- */
/* ... as before ... */
/* Define Rule 2 Query */
/* ------------------- */
/* Create the Query. */
rule_2_qry = lpar_create_lst(LPAR_LST_QEXPR) ;
/* Mark it as a Match Case Query. */
lpar_append_lst(rule_2_qry,
lpar_create_int(LPAR_INT_QEXPR_TYPE,
LKT_QEXPR_MATCH)) ;
/* Add the arguments (we use the reference querylets) */
lpar_append_lst(rule_2_qry, cat_ref_qrys) ;
/* Core query weights are added as querylet weights. */
/* ... the rest as before ... */