Set the NetricsQuery to be performed.
Namespace: NetricsServerInterface
Assembly: NetricsServerInterface (in NetricsServerInterface.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Sub setNetricsQuery( _ ByVal nq As NetricsQuery _ ) |
C# |
---|
public void setNetricsQuery( NetricsQuery nq ) |
C++ |
---|
public: void setNetricsQuery( NetricsQuery nq ) sealed |
J# |
---|
public void setNetricsQuery( NetricsQuery nq ) |
JScript |
---|
public
function setNetricsQuery( nq : NetricsQuery ) |
Remarks
Using the NetricsQuery object is the current preferred method for specifying searches using TIBCO Patterns. 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.
Example
This sample shows how to perform a search of a TIBCO Patterns Engine 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. 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); // Quuery will contain the query string or tokens to be matched against String query = "brown dennis"; // Table is the TIBCO Patterns Engine 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 NetricsSearchOpts opts = new NetricsSearchOpts(); // 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 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"); } } } |