Class NetricsPredicate


  • public class NetricsPredicate
    extends java.lang.Object
    Predicates are used to select or score records based on exact matching tests. Predicates are used in two ways: as a filter to restrict the records to be considered based on some exact match criteria, as a querylet within a query that computes a score based on some exact match criteria. The first is strictly a true/false test that, if false, completely eliminates a record from consideration before the record is scored. The second contributes a score (usually either 0.0 or 1.0 but could be any value between 0.0 and 1.0) that is combined with other querylet scores to determine the overall match score for a record. It acts like an exact matching version of the simple or cognate querylets. Thus the second form doesn't necessarily filter out records even if the predicate match fails. In both cases the Predicate is defined in exactly the same way, the only difference being that for a filtering predicate the result type must be boolean, for a predicate querylet the result type may be boolean or a floating point value.

    Predicates can be specified in two ways, either through a string that defines the predicate or by building it up using this class. The string format is described under the setSearchPredicate method of the NetricsSearchCfg class, how to build predicates using the NetricsPredicate class is described here.

    Let's start with a simple example.

    Imagine you have two fields in a table - name and company. Your business requirements assert that you be able to search only within a given company.

    For example, someone might want to search for the Joe Schmoe who works for Pepsi, not the one who works for Coca-cola. He knows Joe Schmoe works for Pepsi and he wants no results returned for people who work for Coca-cola. This would be an example of a filtering predicate.

    If you performed a fuzzy search on both of the fields, this is not guaranteed. Some not-insignificant value would still be assigned to a match in the company field, and the matching company could be Coca-cola. For instance, searching for the name "Bloke" would have a reasonably strong match with the company Coca-cola. This is not the behavior you want.

    Instead, you want to search only the first name field and set a predicate where the field "company" must match the String "Pepsi," or it will not be evaluated at all. This would pass to the search filter only those records which evaluate to true in the predicate, in this case guaranteeing that only those people who work for Pepsi are searched.

    Here is what the code would look like.
    NetricsSearchCfg tblcfg = new NetricsSearchCfg("tbl");
    NetricsPredicate pred1 = tblcfg.CreateStringOperand("Pepsi");
    NetricsPredicate pred2 = tblcfg.CreateFieldNameOperand("Company");
    NetricsPredicate pred3 = tblcfg.CreatePredicate(pred1,0,pred2);
    tblcfg.SetSearchPredicate(pred3);


    In addition, the relationship between predicates is hierarchical. You can create predicate operands and then combine them with other operators using the CreatePredicate method of the NetricsSearchCfg class.

    In fact, you can nest predicates to an arbitrary depth. Imagine you are searching for Joe Schmoe, and you aren't sure whether he works for Pepsi or Coke, but you are positive it is either Pepsi or Coke and you don't want to see any results from Snapple.

    Here is what the code would look like.
    NetricsSearchCfg tblcfg = new NetricsSearchCfg("tbl");
    NetricsPredicate pred1 = tblcfg.CreateStringOperand("Pepsi");
    NetricsPredicate pred2 = tblcfg.CreateFieldNameOperand("Company");
    // create the pepsi predicate as before
    NetricsPredicate pred3 = tblcfg.CreatePredicate(pred1,NetricsPredicate.EQUALS,pred2);
    NetricsPredicate pred4 = tblcfg.CreatePredicate("Coke");
    // create the coke predicate
    NetricsPredicate pred5 = tblcfg.CreatePredicate(pred2,NetricsPredicate.EQUALS,pred4);
    // combine the two predicates
    NetricsPredicate pred6 = tblcfg.CreatePredicate(pred3,NetricsPredicate.OR,pred5);
    tblcfg.SetSearchPredicate(pred6);


    Remember, predicates can be arbitrarily nested, but not all predicates make sense. For instance, a predicate can be created by using the TOKENIZE operator on a long data type, but will generate an error in the server. Make sure your predicates are not only well formed, but make sense. If you continue to receive error messages, check the error description, and you will get a detailed account of what is causing the error.

    Predicates do not support implicit type conversions. Make sure the operands to each binary operator have the same type. Make sure the operand of each unary operator has the correct type.
    See Also:
    NetricsSearchCfg, NetricsSearchCfg.SetSearchPredicate(String), NetricsQuery.Predicate(NetricsPredicate)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  NetricsPredicate.DistanceUnits
      Units of measure for distance functions.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ABS
      return the absolute value of a double or integer.
      static int AND
      return true if both left and right evaluate to true.
      static int ARGS_APPEND
      append an argument to an argument list.
      static int ARGS_CREATE
      create an argument list with one item.
      static int DIVIDEDBY
      divide left by right.
      static int ENDSWITH
      Check if left argument ends with right argument.
      static int EQUALS
      Check for equality of raw data
      static int FUNC_GEO_DIST
      determine distance between two points on the globe.
      static int FUNC_IF
      if then else operators.
      static int FUNC_TO_SCORE
      normalize a float value into a 0.0 to 1.0 score.
      static int GREATERTHAN
      check if left greater than right.
      static int GREATERTHANOREQ
      check if left greater than or equal to right.
      static int INSEN_ENDSWITH
      Check if left argument ends with right argument, ignoring letter case and diacritics.
      static int INSEN_EQUALS
      Check for equality ignoring letter case and diacritics
      static int INSEN_GREATERTHAN
      check if left > than right ignoring letter case and diacritics.
      static int INSEN_GREATERTHANOREQ
      check if left >= right ignoring letter case and diacritics.
      static int INSEN_ISIN
      letter case insensitive version of ISIN operator.
      static int INSEN_LESSTHAN
      check if left less than right ignoring letter case and diacritics.
      static int INSEN_LESSTHANOREQ
      check of left <= right ignoring letter case and diacritics.
      static int INSEN_LIKE
      As LIKE, but ignores letter case and diacritics.
      static int INSEN_REGEX_MATCH
      As REGEX_MATCH, but ignores letter case and diacritics.
      static int INSEN_STARTSWITH
      Check if left argument starts with right argument, ignoring letter case and diacritics.
      static int ISBLANK
      Check if the argument contains only whitespace and punctuation.
      static int ISIN
      return true if left string is a substring of right string.
      static int LESSTHAN
      check if left side less than right side
      static int LESSTHANOREQ
      check if left less than or equal to right side.
      static int LIKE
      Check if left argument matches right argument as a SQL LIKE pattern.
      static int MINUS
      subtract left from right, or negate value.
      static int NOT
      logical inversion.
      static int OR
      return true if either left or right evaluate to true.
      static int PLUS
      add left to right, concatenate if both are strings.
      static int REGEX_MATCH
      Check if left argument matches right argument as a regular expression.
      static int STARTSWITH
      Check if left argument starts with right argument.
      static int SUBSET
      return true if all strings in block array on left are in block array on right.
      static int SUPERSET
      return true if block array on left contains all strings in block array on right.
      static int TIMES
      multiply left and right.
      static int TOBLK
      convert a value to a character block.
      static int TODATE
      convert value to date.
      static int TODATEEU
      convert value to date assuming it is in European dd/mm/yyyy format.
      static int TODATEEUT
      convert a value to date and time assuming it is in European format.
      static int TODATET
      convert a value to date and time.
      static int TODBL
      convert value to Double (Float).
      static int TOINT
      convert value to integer.
      static int TOKENIZE
      split a string into tokens, returning a block array.
      static int TOTHE
      raise left to the power of right.
    • Method Summary

      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INSEN_EQUALS

        public static final int INSEN_EQUALS
        Check for equality ignoring letter case and diacritics
        See Also:
        Constant Field Values
      • LESSTHAN

        public static final int LESSTHAN
        check if left side less than right side
        See Also:
        Constant Field Values
      • INSEN_LESSTHAN

        public static final int INSEN_LESSTHAN
        check if left less than right ignoring letter case and diacritics.
        See Also:
        Constant Field Values
      • LESSTHANOREQ

        public static final int LESSTHANOREQ
        check if left less than or equal to right side.
        See Also:
        Constant Field Values
      • INSEN_LESSTHANOREQ

        public static final int INSEN_LESSTHANOREQ
        check of left <= right ignoring letter case and diacritics.
        See Also:
        Constant Field Values
      • GREATERTHAN

        public static final int GREATERTHAN
        check if left greater than right.
        See Also:
        Constant Field Values
      • INSEN_GREATERTHAN

        public static final int INSEN_GREATERTHAN
        check if left > than right ignoring letter case and diacritics.
        See Also:
        Constant Field Values
      • GREATERTHANOREQ

        public static final int GREATERTHANOREQ
        check if left greater than or equal to right.
        See Also:
        Constant Field Values
      • INSEN_GREATERTHANOREQ

        public static final int INSEN_GREATERTHANOREQ
        check if left >= right ignoring letter case and diacritics.
        See Also:
        Constant Field Values
      • PLUS

        public static final int PLUS
        add left to right, concatenate if both are strings.
        See Also:
        Constant Field Values
      • MINUS

        public static final int MINUS
        subtract left from right, or negate value.
        See Also:
        Constant Field Values
      • AND

        public static final int AND
        return true if both left and right evaluate to true.
        See Also:
        Constant Field Values
      • OR

        public static final int OR
        return true if either left or right evaluate to true.
        See Also:
        Constant Field Values
      • ISIN

        public static final int ISIN
        return true if left string is a substring of right string.
        See Also:
        Constant Field Values
      • INSEN_ISIN

        public static final int INSEN_ISIN
        letter case insensitive version of ISIN operator.
        See Also:
        Constant Field Values
      • TODATEEU

        public static final int TODATEEU
        convert value to date assuming it is in European dd/mm/yyyy format.
        See Also:
        Constant Field Values
      • TOKENIZE

        public static final int TOKENIZE
        split a string into tokens, returning a block array.
        See Also:
        Constant Field Values
      • SUPERSET

        public static final int SUPERSET
        return true if block array on left contains all strings in block array on right.
        See Also:
        Constant Field Values
      • SUBSET

        public static final int SUBSET
        return true if all strings in block array on left are in block array on right.
        See Also:
        Constant Field Values
      • TOBLK

        public static final int TOBLK
        convert a value to a character block.
        See Also:
        Constant Field Values
      • TODATET

        public static final int TODATET
        convert a value to date and time.
        See Also:
        Constant Field Values
      • TODATEEUT

        public static final int TODATEEUT
        convert a value to date and time assuming it is in European format.
        See Also:
        Constant Field Values
      • ABS

        public static final int ABS
        return the absolute value of a double or integer.
        See Also:
        Constant Field Values
      • ARGS_CREATE

        public static final int ARGS_CREATE
        create an argument list with one item.
        See Also:
        Constant Field Values
      • ARGS_APPEND

        public static final int ARGS_APPEND
        append an argument to an argument list.
        See Also:
        Constant Field Values
      • FUNC_GEO_DIST

        public static final int FUNC_GEO_DIST
        determine distance between two points on the globe.
        See Also:
        Constant Field Values
      • FUNC_TO_SCORE

        public static final int FUNC_TO_SCORE
        normalize a float value into a 0.0 to 1.0 score.
        See Also:
        Constant Field Values
      • STARTSWITH

        public static final int STARTSWITH
        Check if left argument starts with right argument.
        See Also:
        Constant Field Values
      • INSEN_STARTSWITH

        public static final int INSEN_STARTSWITH
        Check if left argument starts with right argument, ignoring letter case and diacritics.
        See Also:
        Constant Field Values
      • ENDSWITH

        public static final int ENDSWITH
        Check if left argument ends with right argument.
        See Also:
        Constant Field Values
      • INSEN_ENDSWITH

        public static final int INSEN_ENDSWITH
        Check if left argument ends with right argument, ignoring letter case and diacritics.
        See Also:
        Constant Field Values
      • LIKE

        public static final int LIKE
        Check if left argument matches right argument as a SQL LIKE pattern.
        % matches 0 or more characters. %% matches a percent sign.
        _ matches exactly one character.
        See Also:
        Constant Field Values
      • INSEN_LIKE

        public static final int INSEN_LIKE
        As LIKE, but ignores letter case and diacritics.
        See Also:
        Constant Field Values
      • REGEX_MATCH

        public static final int REGEX_MATCH
        Check if left argument matches right argument as a regular expression.
        Uses the "ECMAScript 3" regular expression grammar.
        This uses regular-expressions, not ibi™ Patterns fuzzy matching.
        See Also:
        Constant Field Values
      • ISBLANK

        public static final int ISBLANK
        Check if the argument contains only whitespace and punctuation. See the Programmers Guide for a complete list of whitespace and punctuation characters.
        See Also:
        Constant Field Values