ibi Patterns .NET API
Loading...
Searching...
No Matches
NetricsServerInterface.NetricsSearchCfg Class Reference

This class is used with the search methods of the NetricsServerInterface class to configure a query. More...

Public Member Functions

 NetricsSearchCfg (NetricsJoin join_def)
 Configure a joined search against a set of joined tables.
 
 NetricsSearchCfg (String tblname)
 Configure a standard search against a single table.
 
void setNetricsQuery (NetricsQuery nq)
 Set the NetricsQuery to be performed.
 
void addQuery (String query, String[] names)
 Obsolete. Use setNetricsQuery(NetricsQuery) instead.
Adds a NetricsQuery Add a query to the searchCfg object.
 
void addQuery (String query, String[] names, double[] fieldWeights, double queryletWeight, int alignField, String thesaurusName)
 Obsolete. Use setNetricsQuery(NetricsQuery) instead.
Add a query using querylet field weights.
 
void makeDependentQuerylets (int[] multiqueryletIds)
 Obsolete. Use setNetricsQuery(NetricsQuery) instead.
 
void SetSearchPredicate (NetricsPredicate pred)
 Set the search predicate for a given search.
 
void SetSearchPredicate (String expr)
 Set the search predicate from a string.
 

Static Public Member Functions

static NetricsPredicate CreateIntOperand (int i)
 Create a predicate of type int.
 
static NetricsPredicate CreateBoolOperand (bool b)
 Create a predicate of type bool.
 
static NetricsPredicate CreateStringOperand (String s)
 Create a predicate of type String.
 
static NetricsPredicate CreateDoubleOperand (double d)
 Create a predicate of type double.
 
static NetricsPredicate CreateFieldNameOperand (String fn)
 Create a predicate out of a field name.
 
static NetricsPredicate CreatePredicate (NetricsPredicate predl, int op, NetricsPredicate predr)
 Create a predicate by combining two predicates that were previously created.
 
static NetricsPredicate CreateUnaryPredicate (NetricsPredicate pred, int op)
 Create a predicate by combining a single predicate and an operation to be performed on the predicate.
 
static NetricsPredicate CreatePredFunctionCall (int opt_code, params NetricsPredicate[] func_args)
 Generic method for creating predicate function calls.
 
static NetricsPredicate CreateGeoDistance (String lat_field, String long_field, double latitude, double longitude, NetricsPredicate.DistanceUnits units)
 Create a predicate to return the distance between two points.
 
static NetricsPredicate CreateGeoDistance (NetricsPredicate lat1, NetricsPredicate long1, NetricsPredicate lat2, NetricsPredicate long2, NetricsPredicate.DistanceUnits units)
 Create a predicate to return the distance between two points.
 
static NetricsPredicate CreateToScore (NetricsPredicate raw_value, NetricsPredicate zero_score_val, NetricsPredicate one_score_val)
 Create a call to normalize a value into a zero to one score.
 
static NetricsPredicate CreateToScore (NetricsPredicate raw_value, double zero_score_val, double one_score_val)
 Create a call to normalize a value into a zero to one score.
 
static NetricsPredicate CreateSimpleIf (NetricsPredicate condition, NetricsPredicate then_case, NetricsPredicate else_case)
 Create a simple if-then-else clause.
 
static NetricsPredicate CreateIfElseIf (params NetricsPredicate[] sub_exprs)
 Create an if-then-elif-then*-else clause.
 

Detailed Description

This class is used with the search methods of the NetricsServerInterface class to configure a query.

This includes the name of the table or joined set of tables to be searched, the query to be performed and any filtering predicate to be used. It also includes methods for building predicate expressions.

Constructor & Destructor Documentation

◆ NetricsSearchCfg() [1/2]

NetricsServerInterface.NetricsSearchCfg.NetricsSearchCfg ( NetricsJoin  join_def)
inline

Configure a joined search against a set of joined tables.

This configuration is not usable until a query has been added with the setNetricsQuery method.

Parameters
join_defThe definition of the join relation. This must not be null.

◆ NetricsSearchCfg() [2/2]

NetricsServerInterface.NetricsSearchCfg.NetricsSearchCfg ( String  tblname)
inline

Configure a standard search against a single table.

This configuration is not usable until a query has been added with the setNetricsQuery method.

Parameters
tblnameThe name of the table to be searched.

Member Function Documentation

◆ addQuery() [1/2]

void NetricsServerInterface.NetricsSearchCfg.addQuery ( String  query,
String[]  names 
)
inline

Obsolete. Use setNetricsQuery(NetricsQuery) instead.
Adds a NetricsQuery Add a query to the searchCfg object.

This deprecated method can't be used with joined configurations.

Queries are specified at the table level. That is, queries cannot span tables. The AddQuery method works by passing a query string and an array of field names (which are field names in the table you are searching) against which to search. You can add as many query / field-name-array pairs as you like. In the simple case, you can use the AddQuery method to restrict those fields against which you want to search (if some fields are non-searchable for instance).

Another good example is the case where you want to search each query against its associated field. That is, imagine you have a table of music with an artist field, album field, and song field. You might have an "advanced" search where you want to search an artist query against the artist field, album query against the album field, and so on. In fact, you can specify any number of queries and any fields you want them to search against. You can even pass multiple searchCfg objects to the search method, allowing you to search multiple tables at the same time.

Parameters
queryThe query that will be used to search the given field names.
namesThe field names against which the query will be searched (null will search all fields in the table).

◆ addQuery() [2/2]

void NetricsServerInterface.NetricsSearchCfg.addQuery ( String  query,
String[]  names,
double[]  fieldWeights,
double  queryletWeight,
int  alignField,
String  thesaurusName 
)
inline

Obsolete. Use setNetricsQuery(NetricsQuery) instead.
Add a query using querylet field weights.

This deprecated method can't be used with joined configurations.

Parameters
queryThe query that will be used to search the given field names.
namesThe field names against which the query will be searched.
fieldWeightsAn array of doubles which weigh the importance of fields. Use a higher number to weight a given field as more important. The doubles are one per field for the fields specified for this query (the lengths of the 2nd and 3rd parameters to this method should be the same). The valid range for the doubles is from 0.0 to 1.0.
queryletWeightSpecifies the fraction of the entire record score that should come from this querylet. (A value of -1.0 will set each querylet to an equal weight.) If you set a queryletWeight for a query, you must set a queryletWeight for every query for the table.
alignFieldThe field number which this querylet will most likely be found in. This can be used as a hint to the search algorithm (field numbers start at 0).
thesaurusNameThe name of a thesaurus to be used just for this querylet. (A null string will not use a thesaurus for the querylet.)

◆ CreateBoolOperand()

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateBoolOperand ( bool  b)
inlinestatic

Create a predicate of type bool.


See also
NetricsPredicate

◆ CreateDoubleOperand()

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateDoubleOperand ( double  d)
inlinestatic

Create a predicate of type double.

See also
NetricsPredicate

◆ CreateFieldNameOperand()

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateFieldNameOperand ( String  fn)
inlinestatic

Create a predicate out of a field name.

See also
NetricsPredicate

◆ CreateGeoDistance() [1/2]

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateGeoDistance ( NetricsPredicate  lat1,
NetricsPredicate  long1,
NetricsPredicate  lat2,
NetricsPredicate  long2,
NetricsPredicate::DistanceUnits  units 
)
inlinestatic

Create a predicate to return the distance between two points.

This method creates a predicate that uses the Geo-Distance function to determine the distance between two points. The values are given as predicate expressions.

Parameters
lat1The latitude of the first point in degrees.
long1The longitude of the first point in degrees.
lat2The latitude of the second point in degrees.
long2The longitude of the second point in degrees.
unitsThe type of units the distance should be returned in.
See also
NetricsPredicate

◆ CreateGeoDistance() [2/2]

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateGeoDistance ( String  lat_field,
String  long_field,
double  latitude,
double  longitude,
NetricsPredicate::DistanceUnits  units 
)
inlinestatic

Create a predicate to return the distance between two points.

This method creates a predicate that uses the Geo-Distance function to determine the distance between two points, the first point is taken from two record fields, the second is given as fixed constants.

Parameters
lat_fieldThe name of a record field that contains a latitude in degrees. This must have a field type of double.
long_fieldThe name of a record field that contains a longitude in degrees. This must have a field type of double.
latitudeThe latitude of the second point in degrees.
longitudeThe longitude of the second point in degrees.
unitsThe type of units the distance should be returned in.
See also
NetricsPredicate

◆ CreateIfElseIf()

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateIfElseIf ( params NetricsPredicate[]  sub_exprs)
inlinestatic

Create an if-then-elif-then*-else clause.

The predicate if function allows an arbitrary number of conditional clauses. The generalized form of the if function is:

if { [cond,result,]* default-value }

The "cond" expressions are evaluated in order, the "result" value associated with the first one that evaluates to true is returned, if none evaluate to true, "default-value" is returned.

All of the "cond" expressions must evaluate to a boolean value. All of the "result" and the "default-value" expressions must evaluate to the same type. If a single value is given it is treated as a "default-value" with no "cond" "result" clauses. I.e. a single value is just returned as the result of the if function.

This method allows for creation of the generalized if clause by allowing any number of arguments to be passed in.

Parameters
sub_exprsthe sub-expressions for the if function.
See also
NetricsPredicate

◆ CreatePredFunctionCall()

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreatePredFunctionCall ( int  opt_code,
params NetricsPredicate[]  func_args 
)
inlinestatic

Generic method for creating predicate function calls.

This method is a generic method for creating a predicate expression function call. A predicate function is a unary operator that accepts a special arguments list value. Argument lists are created using a special unary operator to create the list with one item, and a binary operator that appends an argument to the list. But it is never necessary to create argument list manually, this method takes care of creating an argument list and calling the function with it.

In fact it should not be necessary to use this method as special purpose methods are available for each predicate function.

Parameters
opt_codeThe operation code identifying the function to be called. The codes are defined in NetricsPredicate.
func_argsThe arguments for the function.
See also
NetricsSearchCfg.CreateGeoDistance(String,String,double,double,NetricsPredicate.DistanceUnits), NetricsSearchCfg.CreateGeoDistance(NetricsPredicate,NetricsPredicate,NetricsPredicate,NetricsPredicate,NetricsPredicate.DistanceUnits), NetricsSearchCfg.CreateSimpleIf, NetricsSearchCfg.CreateIfElseIf, NetricsPredicate

◆ CreatePredicate()

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreatePredicate ( NetricsPredicate  predl,
int  op,
NetricsPredicate  predr 
)
inlinestatic

Create a predicate by combining two predicates that were previously created.

The op parameter is applied between the two predicates. The possible op codes are listed in the table below.

Operator IdDescription
NetricsPredicate.pred_ops.EQUALSThe equality operator (==) - valid for string comparisons as well
NetricsPredicate.pred_ops.INSEN_EQUALSThe equality operator (==) - valid for case insensitive string comparisons as well
NetricsPredicate.pred_ops.LESSTHENThe less than operator (<)
NetricsPredicate.pred_ops.INSEN_LESSTHENThe case insensitive less than operator (<)
NetricsPredicate.pred_ops.LESSTHENOREQThe less that or equal to operator (<=)
NetricsPredicate.pred_ops.INSEN_LESSTHENOREQThe case insensitive less that or equal to operator (<=)
NetricsPredicate.pred_ops.GREATERTHANThe greater than operator (>)
NetricsPredicate.pred_ops.INSEN_GREATERTHANThe case insensitive greater than operator (>)
NetricsPredicate.pred_ops.GREATERTHANOREQThe greater than or equal to operator (>=)
NetricsPredicate.pred_ops.INSEN_GREATERTHANOREQThe case insensitive greater than or equal to operator (>=)
NetricsPredicate.pred_ops.PLUSThe addition operator (+)
NetricsPredicate.pred_ops.MINUSThe subtraction operator (-)
NetricsPredicate.pred_ops.TIMESThe multiplication operator (*)
NetricsPredicate.pred_ops.DIVIDEDBYThe division operator (/)
NetricsPredicate.pred_ops.TOTHEThe exponent operator (^)
NetricsPredicate.pred_ops.ANDThe AND operator (&&)
NetricsPredicate.pred_ops.ORThe OR operator (||)
NetricsPredicate.pred_ops.ISINThe substring operator - detects substring matches of the left operand in the right operand
NetricsPredicate.pred_ops.INSIN_ISINThe substring operator - detects substring matches of the left operand in the right operand ignoring letter case
NetricsPredicate.pred_ops.TOKENIZEThe tokenize operator
NetricsPredicate.pred_ops.SUPERSETThe superset operator
NetricsPredicate.pred_ops.SUBSETThe subset operator

Remember, predicates can nested to an arbitrary depth.

See also
NetricsPredicate

◆ CreateSimpleIf()

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateSimpleIf ( NetricsPredicate  condition,
NetricsPredicate  then_case,
NetricsPredicate  else_case 
)
inlinestatic

Create a simple if-then-else clause.

This creates a simple if-then-else clause using the predicate if function.

Parameters
conditionthe conditional expression.
then_casethe expression value to use if cond is true.
else_casethe expression value to use if cond is false.

◆ CreateStringOperand()

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateStringOperand ( String  s)
inlinestatic

Create a predicate of type String.

See also
NetricsPredicate

◆ CreateToScore() [1/2]

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateToScore ( NetricsPredicate  raw_value,
double  zero_score_val,
double  one_score_val 
)
inlinestatic

Create a call to normalize a value into a zero to one score.

This is a convenience routine for CreateToScore that takes the zero value and one value as double arguments instead of as NetricsPredicate objects.

Parameters
raw_valueThe raw float or double value to be normalized into a valid score.
zero_score_valThe raw value at which the output score becomes zero.
one_score_valThe raw value at which the output score becomes one.
See also
NetricsPredicate

◆ CreateToScore() [2/2]

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateToScore ( NetricsPredicate  raw_value,
NetricsPredicate  zero_score_val,
NetricsPredicate  one_score_val 
)
inlinestatic

Create a call to normalize a value into a zero to one score.

This method creates a call to the "to_score" predicate function. This function is used to convert a float value into a valid score value. It is passed the raw value to be converted, a value that represents a 0.0 score, and a value that represents a 1.0 score. The 0.0 score value may be greater than the 1.0 score value. Values outside the 0.0 value to 1.0 value range are assigned a score of 0.0 or 1.0. Values within the range are assigned a score based on linear interpolation. Some examples:

to_score(10.0, 100.0, 0.0) = 0.1
to_score(10.0, 0.0, 100.0) = 0.9
to_score(12.0, 10.0, 0.0) = 0.0
to_score(1.0, 5.0, 20.0) = 0.0

This is useful in conjunction the geo_distance function to create scores based on the distance between two points. For example to assign a score based on how close a record is to a given location with records more than 25.0 miles away considered a non-match the following could be used:

NetricsPredicate dist_expr ;
"lat", "long",
45.0, 75.0,
NetricsPredicate zero_val ;
NetricsPredicate scoring_pred ;
scoring_pred = NetricsSearchCfg.CreateToScore(dist_expr,
zero_val,
one_val);
Search predicates are used to select or score records based on exact matching tests.
Definition: NetricsPredicate.cs:94
DistanceUnits
Units of measure for distance functions.
Definition: NetricsPredicate.cs:257
This class is used with the search methods of the NetricsServerInterface class to configure a query.
Definition: NetricsSearchCfg.cs:23
static NetricsPredicate CreateGeoDistance(String lat_field, String long_field, double latitude, double longitude, NetricsPredicate.DistanceUnits units)
Create a predicate to return the distance between two points.
Definition: NetricsSearchCfg.cs:544
static NetricsPredicate CreateDoubleOperand(double d)
Create a predicate of type double.
Definition: NetricsSearchCfg.cs:390
static NetricsPredicate CreateToScore(NetricsPredicate raw_value, NetricsPredicate zero_score_val, NetricsPredicate one_score_val)
Create a call to normalize a value into a zero to one score.
Definition: NetricsSearchCfg.cs:665
Parameters
raw_valueThe raw float or double value to be normalized into a valid score.
zero_score_valThe raw value at which the output score becomes zero.
one_score_valThe raw value at which the output score becomes one.
See also
NetricsPredicate

◆ CreateUnaryPredicate()

static NetricsPredicate NetricsServerInterface.NetricsSearchCfg.CreateUnaryPredicate ( NetricsPredicate  pred,
int  op 
)
inlinestatic

Create a predicate by combining a single predicate and an operation to be performed on the predicate.

The possible op codes are listed in the table below.

Operator IdDescription
NetricsPredicate.pred_ops.MINUSNegate - equivalent to multiplying by -1
NetricsPredicate.pred_ops.NOTNot - logical negation (!)
NetricsPredicate.pred_ops.TOINTTo int type (cast)
NetricsPredicate.pred_ops.TODBLTo float type (cast)
NetricsPredicate.pred_ops.TODATETo date type
NetricsPredicate.pred_ops.TODATEEUTo EU date type (European data format)
NetricsPredicate.pred_ops.TOKENIZETokenize
NetricsPredicate.TOBLKTo block type
NetricsPredicate.TODATETTo date type, with time (default format yyyy/mm/dd HH:MM:SS)
NetricsPredicate.TODATEEUTTo EU date type, with time
NetricsPredicate.ABSReturn Absolute Value of operand

Remember, predicates can nested to an arbitrary depth.

See also
NetricsPredicate

◆ makeDependentQuerylets()

void NetricsServerInterface.NetricsSearchCfg.makeDependentQuerylets ( int[]  multiqueryletIds)
inline

Obsolete. Use setNetricsQuery(NetricsQuery) instead.

This deprecated method can't be used with joined query configurations. It was used when the same field was present in two or more querylets.

This function allows the user to specify which querylets are "dependent" on each other (i.e. only one or the other of the querylets can match a given stretch of text in the record). If this function is not used, the querylet dependencies will be automatically detected (by looking for overlapping fieldsets), but it is almost always better to use this function, even if the querylet dependencies are trivial.

Parameters
multiqueryletIdsAny two querylets that are dependent are part of the same "multiquerylet." The multiqueryletIds parameter should be the same length as the number of querylets added to the NetricsSearchCfg. Each position in the array is the ID of the multiquerylet that querylet belongs to. In this way, if any two positions in the array have the same multiquerylet id, they will be added to the same multiquerylet and will thus be dependent querylets. It is an error to use multiquerylet ids less than 0 or greater than the number of querylets added to the NetricsSearchCfg object. For example, with querylets "First Name", "Last Name", and "Address", the array {0,0,1} would make the first two querylets dependent and the last querylet independent of the other two.

◆ setNetricsQuery()

void NetricsServerInterface.NetricsSearchCfg.setNetricsQuery ( NetricsQuery  nq)
inline

Set the NetricsQuery to be performed.

Using the NetricsQuery object is the current preferred method for specifying searches using ibi™ Patterns - Search . The AddQuery and makeDependentQuerylets methods are deprecated. This must be called exactly once for each NetricsSearchCfg object. The query is applied to the table, or joined set of tables for this search configuration.

This sample shows how to perform a search of an ibi™ Patterns - Search table by using the setNetricsQuery method.

// In this example a Simple search will be configured. The sample demonstrates searching
// the names table for the query string "brown dennis". The fields to matched against this
// string are "last" and "first". The weight for "last" is 1.0 and for "first" is .5. In this
// case the "last" name will have a higher importance in the score so that records with a "last"
// match will have a higher similarity score than those of "first" and will appear higher in the
// result set in the response.
class MyClass
{
private static NetricsServerInterface.NetricsServerInterface si = null; <br>
public static void Main()
{
try
{
String host = "localhost";
int port = 5051;
// Quuery will contain the query string or tokens to be matched against
String query = "brown dennis";
// Table is the <i>ibi Patterns - Search</i> table to be search/matched against query
String table = "names";
// FieldNames contain the fields within the table to be searhed/matched against.
// If fieldNames is set to null then all fields will be searched/matched against
String[] fieldNames = {"last" , "first"};
// FieldWeights is an array that must be the same length as fields and contain the
// weights (0.0 - 1.0) of each field that contribute to the overall score of the result
double[] fieldWeights = { 1.0, .5 };
// Create NetricsSearchOpts object using the defaults
// Create the NetricsSearchCfg pointing to the table to be searched/matched against
NetricsSearchCfg tblCfg = new NetricsSearchCfg(table);
// Add a Simple query to the NetricsSearchCfg using the query, fieldNames and fieldWeights
tblCfg.setNetricsQuery(NetricsQuery.Simple(query, fieldNames, fieldWeights));
// Perform the search/match using the NetricsSearchCfg and NetricsSearchOpts
NetricsSearchResponse resp = si.search(tblCfg, opts);
String s = "";
// Get the results of the search/match
// Create viables for result processing
String[] xfieldNames;
String[] xfields;
// Iterate through the result records
for (int i = 0; i < res.Length; i++)
{
// Get the fieldNames in the result record
xfieldNames = res[i].getFieldNames();
// Get the data for each fieldName in result record
xfields = res[i].getFields();
// Get the score for this result record
double score = res[i].getMatchScore();
// Build the printline for the result record
s = s + "Rank=" + i + ", Score=" + score.ToString();
for (int x = 0; x < xfields.Length; x++)
{
s = s + ", " + xfieldNames[x] + "=" + xfields[x];
}
s = s + "\n";
}
Console.WriteLine(s);
}
catch (NetricsException e)
{
Console.Write(e.getErrorDescription() + "\n");
}
}
}
String[] getFields()
Can be used to get the content of a record.
Definition: NetricsBaseRecord.cs:349
A NetricsException is thrown whenever an error occurs.
Definition: NetricsException.cs:32
String getErrorDescription()
Get the description of the error.
Definition: NetricsException.cs:110
String[] getFieldNames()
Returns an array of Strings which are the names of the fields for the source table of the record.
Definition: NetricsMappedRecord.cs:120
NetricsQuery objects are used to implement the complex query structures introduced with release 4....
Definition: NetricsQuery.cs:66
static NetricsQuery Simple(String qstr, String[] fldnames, double[] fldweights)
Create a Simple Query Expression Node.
Definition: NetricsQuery.cs:397
void setNetricsQuery(NetricsQuery nq)
Set the NetricsQuery to be performed.
Definition: NetricsSearchCfg.cs:170
This class is used to configure search options which apply for the overall search (for all tables bei...
Definition: NetricsSearchOpts.cs:17
This class represents the ibi™ Patterns - Search Server's response to a search command.
Definition: NetricsSearchResponse.cs:23
NetricsSearchResult[] getSearchResults()
Get the records returned by the search.
Definition: NetricsSearchResponse.cs:194
This class extends NetricsMappedRecord adding information relevant to a search result (match score,...
Definition: NetricsSearchResult.cs:24
double getMatchScore()
Get the overall match score for this record.
Definition: NetricsSearchResult.cs:236
Base class for all interactions with the ibi™ Patterns - Search Server.
Definition: NetricsServerInterface.cs:62
ibi™ Patterns - Search .NET Interface Overview.
Definition: BaseObjectStats.cs:14
See also
NetricsQuery

◆ SetSearchPredicate() [1/2]

void NetricsServerInterface.NetricsSearchCfg.SetSearchPredicate ( NetricsPredicate  pred)
inline

Set the search predicate for a given search.

This is the one predicate which must evaluate to true for any record returned by the search. In other words, the ibi™ Patterns - Search Server will return the "MatchesRequested" best records which evaluated to true for the given predicate.

See also
NetricsPredicate, NetricsSearchCfg.SetSearchPredicate(String)

Sample code

◆ SetSearchPredicate() [2/2]

void NetricsServerInterface.NetricsSearchCfg.SetSearchPredicate ( String  expr)
inline

Set the search predicate from a string.

In addition to building the search predicate piece by piece the entire predicate can be defined as a string using a SQL like syntax. The basic items in the syntax are:

?TRUE?, ?FALSE?Boolean constant values are true and false enclosed in question marks. Letter case insensitive
123,0777,0x8FFFInteger constant values. They follow the standard "C" and C# conventions for decimal, Octal and Hex integers.
123.45, 0.17e-10Floating point values. They follow the standard "C" and C# conventions for fixed and scientific notation values.
"string"string constants are enclosed in double quotes. The basic XML/HMTL encoding scheme is used to represent the double quote character (") itself and other special characters. The numeric conventions: &#ddd; and &#xhh; are recognized and the entity names: quot, amp, lt, gt and apos are recognized. Note that you must NOT insert an encoded NULL character into the string as this is a NULL terminated string value.
:"byte block"A byte block is specified by preceding a quoted string value with a colon (:) character. The length of the block is computed automatically. All non-valid string characters must be encoded using the XML/HTML like encodings as defined for strings.
#2Table fields specified by numeric position. An integer value preceded with the pound (#) character is used to represent the table field at the indicated column position. Like array indexes in "C" and C# these field numbers are zero based.
$"first name"Table fields specified by field name. A quoted string value (see string description above) preceded by the dollar ($) sign. The string value is the field name.
[ :"block 1", :"block 2" ]
[ :]
Block arrays. A comma separated list of blocks enclosed in square brackets ([]). To specify a Block array with zero entries use an open bracket followed by colon close bracket (:]) no space between the colon and close bracket.
{ expr 1, expr 2 }Argument Lists. A comma separated list of expressions enclosed in curly braces ({}) is a special notation used to create argument lists for predicate functions.


Predicate expressions are defined in a typical manner. E.g.

INT $"age" > 21


specifies all records where the "age" field is greater than 21 (if the field "age" was of type int or float the INT conversion operator would not be necessary). Parenthesis can be used to group operations into more complex expressions:

((INT $"age" + INT $"years experience") / 2) - 1 >= 21


Operators are left associative, that is:

2 + 3 + 12


is equivalent to:

(2 + 3) + 12



Operators have precedence similar to those in "C" C# and C++. So:

12 + 2 * 3


is the same as:

12 + (2 * 3)


Special unary operators called predicate functions take an argument list as their single argument:

geod { DBL $"lat", DBL $"long", 45.0, 75.0, "miles" } < 25.0

calls the geo-distance function with an argument list consisting of five arguments and test if the value is less than 25 miles.
Some key differences between the precedence of predicate operators and the "C" language family of operators are:

  • All unary operators have higher precedence (bind tighter) than binary operators, this includes all predicate function operators.
  • + has slightly higher precedence than - (minus), thus
    a - b + c
    is the same as
    a - (b + c)
    not
    (a - b) + c
  • similarly multiply (*) has slightly higher precedence than divide (/)
  • All comparison operators have the same precedence.


The binary operators listed from highest precedence to lowest are:

operatorsdescription
**raise to power
*multiple
/divide
+addition for numbers, concatenation for strings
-subtraction
=, ==, ~=, >, ~>, >=, ~>=, <, ~<, <=, ~<= SUBSET, SUPERSET, IN, I_INComparison operators, "=" and "==" are synonyms. Comparison operators prefixed with ~ ("I_" in the case of the IN operator) perform letter case insensitive comparisons.
ANDLogical and joining operator, similar to the C# && operator
ORLogical or joining operator, similar to the C# || operator


The unary operators are:

operatordescription
+arithmetic positive, this does nothing
-arithmetic negation
NOTlogical inverse
UPPERconvert character string/byte block to upper case
LOWERconvert character string/byte block to lower case
INTconvert value to integer
DBL DOUBLE FLOATconvert value to floating point. These are all synonyms for the same operation.
DATEconvert value to a date.
DATEEU EUDATEconvert value to a date. String and byte block format dates are assumed to be in European format. These are synonyms for the same operation
BLOCKconvert value to a byte block.
SPLIT TOKENIZEsplit a string or block into a block array with each element of the array being a word from the string.
ABSreturn the absolute value of a number.


The names of all operators are letter case insensitive. For more information on these operations see NetricsPredicate.

The final example from NetricsPredicate as a string predicate would be:

NetricsSearchCfg tblcfg = new NetricsSearchCfg("tbl");<br/>
tblcfg.SetSearchPredicate("$\"Company\" == \"Pepsi\" or $\"Company\" == \"Coke\"");
void SetSearchPredicate(NetricsPredicate pred)
Set the search predicate for a given search.
Definition: NetricsSearchCfg.cs:798

This sample shows how to perform a search of a ibi Patterns - Search table using a predicate to filter the result set to only include those records from the state of CA.

// This is an example of a multi-query where different query strings can be used in a search across
// different fields within a table. This requires first configuring a Simple query for each query
// string along with the fields to be searched and then either "And" or "Or" them together. In this
// we will query the "names" table using a query string against the "last" field and a another query
// string against the "first" field. Each of these queries are referred to as a querylet. We will
// apply a higher weight to the "last" field querylet and apply a the "nicknames" thesuaurs to the
// "first" field querylet treating the related terms within the thesaurus as equivalent. We are also
// using a predicate for this query which is set to limit the results to only those records that have
// the "state" field equal to "CA".
using System;
class MyClass
{
public static void Main()
{
try
{
String host = "localhost";
int port = 5051;
// Table is the <i>ibi Patterns - Search</i> table to be search/matched against query
String table = "names";
// Going to use 2 NetricsQuery for the search configuration
NetricsQuery[] nqs = new NetricsQuery[2];
// Create NetricsSearchOpts object using the defaults
// Set up the query to use the nicknames thesaurus. i.e. "Den" is equivalent to "Dennis"
opts.useThesaurus("nicknames");
// Create the NetricsSearchCfg pointing to the table to be searched/matched against
NetricsSearchCfg tblCfg = new NetricsSearchCfg(table);
// Query will contain the query string for the first querylet which is "last
String query = "brown";
// FieldNames contain the fields within the table to be searhed/matched against.
// If fieldNames is set to null then all fields will be searched/matched against
String[] fieldNames = { "last" };
// Create a Simple query for the "last" names search
nqs[0] = NetricsQuery.Simple(query, fieldNames, null);
// Set up the second Simple query
query = "den";
fieldNames[0] = "first";
nqs[1] = NetricsQuery.Simple(query, fieldNames, null);
// QueryletWeights is an array that must be the same length as the number of querylets
// and is the weight applied to each querylet in the search which impacts the similarity
// scrore. In this case there will be two querylets that will be ANDed together to create
// a single search configuration
double[] queryletWeights = { 1.0, 1.0 };
// Now AND the two Simple querys together to create the final NetricsQuery for the search
NetricsQuery nqAnded = NetricsQuery.And(queryletWeights, nqs);
// Set the NetricsSearchCfg;
tblCfg.setNetricsQuery(nqAnded);
// Limit the result set to include only records whose "state" field equals "CA"
tblCfg.SetSearchPredicate("$\"state\" == \"CA\"");
// Perform the search/match using the NetricsSearchCfg and NetricsSearchOpts
NetricsSearchResponse resp = si.search(tblCfg, opts);
String s = "";
// Get the results of the search/match
// Create viables for result processing
String[] xfieldNames;
String[] xfields;
// Iterate through the result records
for (int i = 0; i < res.Length; i++)
{
// Get the fieldNames in the result record
xfieldNames = res[i].getFieldNames();
// Get the data for each fieldName in result record
xfields = res[i].getFields();
// Get the score for this result record
double score = res[i].getMatchScore();
// Build the printline for the result record
s = s + "Rank=" + i + ", Score=" + score.ToString();
for (int x = 0; x < xfields.Length; x++)
{
s = s + ", " + xfieldNames[x] + "=" + xfields[x];
}
s = s + "\n";
}
Console.WriteLine(s);
}
catch (NetricsException e)
{
Console.Write(e.getErrorDescription() + "\n");
Console.Write(e.ToString() + "\n");
}
}
}
static NetricsQuery And(double[] weights, NetricsQuery[] nqs)
Create an AND Query Expression Node.
Definition: NetricsQuery.cs:581
void useThesaurus(String name)
Use the specified thesaurus in determining matching records.
Definition: NetricsSearchOpts.cs:1267
NetricsSearchResponse search(NetricsSearchCfg cfg, NetricsSearchOpts opts)
Version of search to search a single table.
Definition: NetricsServerInterface.cs:1321
See also
NetricsPredicate