Open topic with navigation

TIBCO® Patterns 6.1.2

# Query Construction

With the advent of version 4.1 of the TIBCO Patterns servers, query construction has simplified dramatically. This section outlines the type of construction that is now suggested and is supported in the future. A query consists of a tree of "score generators" and "score combiners." A score generator takes data from a table and computes a score (between 0.0 and 1.0). The currently available score generators are Simple, Cognate, Attribute, and Predicate. There is a special case of the simple score generator, called a custom scorer, which is used to compare two dates. A score combiner is used to combine previously computed scores, the simplest case of which is an arithmetic mean. The available score combiners are AND, OR, RECWGT, and Record Linkage (RLINK).

The user must construct a query tree such that all the leaves in the tree are score generators and all the branches of the tree are score combiners. In practice most score trees are just one level deep - with a set of score generators combined using a single score combiner.

For a concrete example, consider a database with the following fields:

| • | First Name

| • | Last Name

| • | Social Security Number

| • | House Number

| • | Street Name

| • | City

and a search application which provides the user three text entry boxes labeled Name, Address, and SSN.

    lpar_t ANDquery,ANDqueryargs,simpquery,sq,sf;
    unsigned char *name,*address,*ssn;
    unsigned char *name_fields[] =    { "First Name",
                                        "Last Name" };
    unsigned char *ssn_fields[] =     { "Social Security Number" };
    unsigned char *address_fields[] = { "House Number",
                                        "Street Name",
                                        "City" };
    name    = get_name_box();
    address = get_address_box();
    ssn     = get_ssn_box();
    ANDqueryargs=lpar_create_lst(LPAR_LST_QEXPR_ARGS);
    /* Name simpquery */
    simpquery=lpar_create_lst(LPAR_LST_SIMPLEQUERY);
    sq=lpar_create_blk(LPAR_BLK_SEARCHQUERY,name,strlen(name));
    lpar_append_lst(simpquery,sq);
    sf=lpar_create_strarr(LPAR_STRARR_FIELDNAMES,name_fields,2);
    lpar_append_lst(simpquery,sf);
    lpar_append_lst(ANDqueryargs,simpquery);
    /* SSN simpquery */
    simpquery=lpar_create_lst(LPAR_LST_SIMPLEQUERY);
    sq=lpar_create_blk(LPAR_BLK_SEARCHQUERY,ssn,strlen(ssn));
    lpar_append_lst(simpquery,sq);
    sf=lpar_create_strarr(LPAR_STRARR_FIELDNAMES,ssn_fields,1);
    lpar_append_lst(simpquery,sf);
    lpar_append_lst(ANDqueryargs,simpquery);
    /* Address simpquery */
    simpquery=lpar_create_lst(LPAR_LST_SIMPLEQUERY);
    sq=lpar_create_blk(LPAR_BLK_SEARCHQUERY,address,strlen(address));
    lpar_append_lst(simpquery,sq);
    sf=lpar_create_strarr(LPAR_STRARR_FIELDNAMES,address_fields,3);
    lpar_append_lst(simpquery,sf);
    lpar_append_lst(ANDqueryargs,simpquery);
    ANDquery=lpar_create_lst(LPAR_LST_QEXPR);
    lpar_append_lst(ANDquery,lpar_create_int(LPAR_INT_QEXPR_TYPE,LKT_QEXPR_AND));
    lpar_append_lst(ANDquery,ANDqueryargs);

Here an AND combiner containing three simple queries has been built. Each querylet contains a SEARCHQUERY text block and a field selection array. Notice that there does not need to be a one to one mapping between record fields and querylets. When one querylet lists multiple fields in its field set, those fields are concatenated and the querylet text is compared against this concatenated field string.

We now outline all the different score generators and combiners and the parameters they take before giving a more complicated example.

Subtopics

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO® Patterns

Copyright © 2010-2025. Cloud Software Group, Inc. All Rights Reserved.