Create an Predicate Query Expression Node from a string predicate
Namespace: NetricsServerInterface
Assembly: NetricsServerInterface (in NetricsServerInterface.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Shared Function Predicate( _ ByVal expr As String _ ) As NetricsQuery |
C# |
---|
public static NetricsQuery Predicate( string expr ) |
C++ |
---|
public: static NetricsQuery Predicate( String expr ) |
J# |
---|
public static NetricsQuery Predicate( string expr ) |
JScript |
---|
public static
function Predicate( expr : String ) : NetricsQuery |
Parameters
- expr
- the string predicate expression
Example
This sample shows a AND query using both a Simple and Predicate query and highlights the difference between a predicate filter and a predicate query.
![]() | |
---|---|
// This is an example of a AND query using both a Simple query and a Predicate query. The Predicate // query uses the same expression as a predicate filter but differs in the following respect. A predicate // filter eliminates the record from the result set if the record fails the predicate test. With a // Predicate query the result score is 0.0 if the test fails and a 1.0 if the test passes. The record is not // eliminated from the result set but the score is set according to the Predicate outcome. // // We first configure a Simple using the query string along with the fields to be searched and then configure // the Predicate query and either "And" or "Or" them together. In this example we will query the "names" table // using a query string against the "last" field. We will then configure a Predicate query looking for a "2001" // in the "dob" field. Each of these queries are referred to as a querylet. We will apply an equal weight of 1.0 // to each of the querylets. We are also using a filter predicate for the overall query which is set to limit the // results to only those records that have the "state" field equal to "CA". using System; using NetricsServerInterface; class MyClass { private static NetricsServerInterface.NetricsServerInterface si = null; public static void Main() { try { String host = "localhost"; int port = 5051; si = new NetricsServerInterface.NetricsServerInterface(host, port); // Table is the TIBCO Patterns Engine 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 NetricsSearchOpts opts = new NetricsSearchOpts(); // 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 a Predicate query query = "den"; fieldNames[0] = "first"; nqs[1] = NetricsQuery.Predicate("\"2001\" IN $\"dob\""); // 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 NetricsSearchResult[] res = resp.getSearchResults(); // 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"); } } } |