Search predicates are used to select or score records based on exact matching tests.


Namespace: NetricsServerInterface
Assembly: NetricsServerInterface (in NetricsServerInterface.dll)

Syntax

Visual Basic (Declaration)
Public Class NetricsPredicate
    Implements INetricsPredicate
C#
public class NetricsPredicate : INetricsPredicate
C++
ref class NetricsPredicate : INetricsPredicate
J#
public class NetricsPredicate implements INetricsPredicate
JScript
public class NetricsPredicate extends INetricsPredicate

Remarks

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 completely eliminates a record from consideration if false 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.

Search 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.

 Copy Code
                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.

 Copy Code
                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,0,pred2);
                NetricsPredicate pred4 = tblcfg.CreatePredicate("Coke");
                // create the coke predicate
                NetricsPredicate pred5 = tblcfg.CreatePredicate(pred2,0,pred4);
                // combine the two predicates
                NetricsPredicate pred6 = tblcfg.CreatePredicate(pred3,10,pred5);
                tblcfg.SetSearchPredicate(pred6);
                

Remember, predicates can be arbitrarily nested, but all predicates don't make sense. The predicate made by using the ABS operator on a text data type, for instance, can be created 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 for what is causing the error.

Inheritance Hierarchy

System.Object
   NetricsServerInterface.NetricsPredicate

Thread Safety

Public static (Shared in Visual Basic)staticShared members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

See Also